I managed to use a proxy server with selenium for chrome using the code below:
chromedriver = "C:/Seltests/chromedriver"
os.environ["webdriver.chrome.driver"] = chromedriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=141.0.175.141:443')
driver = webdriver.Chrome(chrome_options=chrome_options)
However, I would like to know if it is possible to change that proxy to a new one during run-time. Or if there is any other way of doing this so it allows me to. I'm thinking that using the code above I would have to have the browser close then re-open to start a new session and use another proxy? Please help :)
You will have to re-launch the browser instance in order to achieve this. Wherever you want to change the proxy insert the following code:
driver.quit()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=<new proxy>')
driver = webdriver.Chrome(chrome_options=chrome_options)
This will close the current browser and launch a new one with the new proxy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With