Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proxy: Selenium + Python, Firefox

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 tried:

profile = webdriver.FirefoxProfile() 
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "54.213.66.208")
profile.set_preference("network.proxy.http_port", 80)
profile.update_preferences() 
driver = webdriver.Firefox(profile)
like image 413
Michele Spina Avatar asked Sep 10 '13 13:09

Michele Spina


People also ask

How to set proxy for Firefox in Selenium?

There are two ways of setting up Firefox Proxy using Selenium: By adding preferred Proxy Server Host and Port details to FirefoxOptions class, that can be later used in the tests. By setting Firefox Profile using FirefoxProfile class. By setting up desired capabilities.

What is proxy in selenium?

A proxy is an intermediary between client requests and server responses. Proxies are primarily used to ensure privacy and encapsulation between numerous interactive systems. A proxy can also provide an added layer of security by operating as a firewall between client and web servers.

Which of the following codes is used in selenium to configure the use of proxy?

Following piece of code used to set proxy in Selenium. ChromeOptions option = new ChromeOptions(); Proxy proxy = new Proxy(); proxy. setHttpProxy("localhost:5555"); option. setCapability(CapabilityType.


1 Answers

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.

like image 128
amitdatta Avatar answered Nov 09 '22 04:11

amitdatta