how do i set proxy for chrome in python webdriver

sarbo picture sarbo · Jul 12, 2012 · Viewed 100.9k times · Source

I'm using this code:

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)

to set proxy for FF in python webdriver. This works for FF. How to set proxy like this in Chrome? I found this exmaple but is not very helpful. When i run the script nothing happens (Chrome browser is not started).

Answer

Ivan picture Ivan · Aug 6, 2012
from selenium import webdriver

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

chrome = webdriver.Chrome(options=chrome_options)
chrome.get("http://whatismyipaddress.com")