Running selenium behind a proxy server Running selenium behind a proxy server selenium selenium

Running selenium behind a proxy server


You need to set desired capabilities or browser profile, like this:

profile = webdriver.FirefoxProfile()profile.set_preference("network.proxy.type", 1)profile.set_preference("network.proxy.http", "proxy.server.address")profile.set_preference("network.proxy.http_port", "port_number")profile.update_preferences()driver = webdriver.Firefox(firefox_profile=profile)

Also see related threads:


The official Selenium documentation (http://docs.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy) provides clear and helpful guidelines about using a proxy.For Firefox (which is the browser of choice in your sample code) you should do the following:

from selenium import webdriverfrom selenium.webdriver.common.proxy import *myProxy = "host:8080"proxy = Proxy({    'proxyType': ProxyType.MANUAL,    'httpProxy': myProxy,    'ftpProxy': myProxy,    'sslProxy': myProxy,    'noProxy': '' # set this value as desired    })driver = webdriver.Firefox(proxy=proxy)


This will do the job:

import seleniumfrom selenium.webdriver.common.proxy import *proxyHost = "my.proxy.host or IP"proxyPort = "55555"fp = webdriver.FirefoxProfile()fp.set_preference("network.proxy.type", 1)#fp.set_preference("network.proxy.http", proxyHost) #HTTP PROXY#fp.set_preference("network.proxy.http_port", int(proxyPort))#fp.set_preference("network.proxy.ssl", proxyHost) #SSL  PROXY#fp.set_preference("network.proxy.ssl_port", int(proxyPort))fp.set_preference('network.proxy.socks', proxyHost) #SOCKS PROXYfp.set_preference('network.proxy.socks_port', int(proxyPort))fp.update_preferences()driver = webdriver.Firefox(firefox_profile=fp)driver.get("http://www.whatismyip.com/")