Skip to content Skip to sidebar Skip to footer

Selenium Chrome & Firefox Webdriver: Set Https Proxy In Python

I've done plenty of searching however there is a lot of confusing snippets out there that are very similar. I've attempted to use the DesiredCapabilities, ChromeOptions, Options an

Solution 1:

According to the latest documentation (Jul 2020) you set the DesiredCapabilities for either FIREFOX or CHROME.

I've tested it for Firefox. You can check your browser's connection settings afterwards to validate the proxy was set correctly.

from selenium import webdriver

PROXY = "<HOST>:<PORT>"# HOST can be IP or name
webdriver.DesiredCapabilities.FIREFOX['proxy'] = {
    "httpProxy": PROXY,
    "ftpProxy": PROXY,
    "sslProxy": PROXY,    # this is the https proxy"proxyType": "MANUAL",
}

with webdriver.Firefox() as driver:
    # Open URL
    driver.get("https://selenium.dev")

The proxy-dict itself is documented in the Selenium wiki. You'll see here that the attribute sslProxy sets the proxy for https.

I haven't tested it for Chrome though. If it shouldn't work, you may find clues in Google's ChromeDriver documentation. According to this you also need to instantiate the webdriver with the desired_capabilites parameter (which is then actually very similar to your example, so this is now more of a guess than a proven solution):

caps = webdriver.DesiredCapabilities.CHROME.copy()
caps['proxy'] = ... # like described above
driver = webdriver.Chrome(desired_capabilities=caps)
driver.get("https://selenium.dev")

Post a Comment for "Selenium Chrome & Firefox Webdriver: Set Https Proxy In Python"