2
driver = webdriver.Firefox()
for x in range(10):
    driver.get("mysite.com")

Is there a way to change the proxy on every connection to "mysite.com" in the range 10, but without closing the driver and reopening it, but just changing the settings of proxy?

0

1 Answer 1

5

You need to import the following:

from selenium.webdriver.common.proxy import *

Then setup the proxies:

myProxy = "xx.xx.xx.xx:xxxx"

proxy = Proxy({
    'proxyType': ProxyType.MANUAL,
    'httpProxy': myProxy,
    'ftpProxy': myProxy,
    'sslProxy': myProxy,
    'noProxy': '' # set this value as desired
    })

Then call the webdriver.Firefox() function as follows:

driver = webdriver.Firefox(proxy=proxy)
driver.get("http://www.google.com")

Or you can use tor browser it will switch the proxy automatically

Sign up to request clarification or add additional context in comments.

3 Comments

yeah but since I have multiple proxies that changes at every range, it'd change the proxy only reopening the webdriver... and I need that webdriver remains opened.. is that possible?
i just need a way to change proxy while the browser is opened

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.