I can't connect using proxies via Selenium Firefox WebDriver.
With this configuration, the connection is generated but NOT via the proxy but the local server.
There are two questions on this matter and this documentation, but none seem to have solved this for python3:
def selenium_connect():
proxy = "178.20.231.218"
proxy_port = 80
url = "https://www.whatsmyip.org/"
fp = webdriver.FirefoxProfile()
# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http",proxy)
fp.set_preference("network.proxy.http_port",proxy_port)
fp.update_preferences()
driver = webdriver.Firefox(firefox_profile=fp)
driver.get(url)
I'm using Firefox webdriver version 52.0.2 and Python 3.7 and a standard Ubuntu 16.04 Docker environment.
The leading web framework, Selenium, may configure your proxy server to support the testing requirements. If Selenium powers the test, then an HTTP request will generate a browser. The HTTP request runs several proxies at a time and will send the localized results.
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.
Don’t you need to set the proxy with DesiredCapabilities and not in a FirefoxProfile? Like the following.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.proxy import Proxy
proxy_to_use= "xxx.xxx.xxx.xxx"
desired_capability = webdriver.DesiredCapabilities.FIREFOX
desired_capability['proxy'] = {
'proxyType': "manual",
'httpProxy': proxy_to_use,
'ftpProxy': proxy_to_use,
'sslProxy': proxy_to_use
}
browser = webdriver.Firefox(capabilities=desired_capability)
browser.get(“http://www.whatsmyip.org”)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With