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?

Allexj
  • 1,375
  • 6
  • 14
  • 29

1 Answers1

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

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
  • 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? – Allexj Aug 28 '17 at 15:57
  • i just need a way to change proxy while the browser is opened – Allexj Aug 28 '17 at 16:17
  • 1
    https://stackoverflow.com/questions/19565426/how-to-change-firefox-web-driver-proxy-settings-in-runtime – Shubham Jain Aug 28 '17 at 16:19