Proxy: Selenium + Python, Firefox
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.
Try this for firefox/geckodriver:
proxy = "212.66.117.168:41258"firefox_capabilities = webdriver.DesiredCapabilities.FIREFOXfirefox_capabilities['marionette'] = Truefirefox_capabilities['proxy'] = { "proxyType": "MANUAL", "httpProxy": proxy, "ftpProxy": proxy, "sslProxy": proxy}driver = webdriver.Firefox(capabilities=firefox_capabilities)
And for Chrome you can use:
proxy = "212.66.117.168:41258"prox = Proxy()prox.proxy_type = ProxyType.MANUALprox.http_proxy = proxyprox.socks_proxy = proxyprox.ssl_proxy = proxycapabilities = webdriver.DesiredCapabilities.CHROMEprox.add_to_capabilities(capabilities)driver = webdriver.Chrome(desired_capabilities=capabilities)
Your problem is on the driver init. Try webdriver = webdriver.Firefox(firefox_profile=profile)
All the other code is OK and you can also remove profile.update_preferences()
line.
I found YOUR solution with a 2 minute google search. How much time did you spend waiting for? :D
Your problem is that you maybe read code from other langs but Python. Replace this webdriver.Firefox(profile)
with webdriver.Firefox(firefox_profile=profile)
.
Your code should be:
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(firefox_profile=profile)