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,173
  • 5
  • 13
  • 26
  • See: [How do I do X?](https://meta.stackoverflow.com/questions/253069/whats-the-appropriate-new-current-close-reason-for-how-do-i-do-x) The expectation on SO is that the user asking a question not only does research to answer their own question but also shares that research, code attempts, and results. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! See also: [ask] – JeffC Aug 28 '17 at 13:39

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
  • 14,804
  • 9
  • 73
  • 115
  • 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