Proxy: Selenium + Python, Firefox

后端 未结 3 476
谎友^
谎友^ 2020-12-05 08:10

How can I redirect the traffic of Firefox launched by Selenium in Python to a proxy? I have used the solutions suggested on the web but they don\'t work!

I have tri

3条回答
  •  萌比男神i
    2020-12-05 09:01

    You need to import the following:

    from selenium.webdriver.common.proxy import Proxy, ProxyType
    

    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")
    

    Don't remember where exactly I found this solution, but its out there somewhere. Will surely provide a link if I find it again. Just took this part out of my code.

提交回复
热议问题