Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set proxy for chrome in python webdriver?

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).

like image 789
sarbo Avatar asked Jul 12 '12 10:07

sarbo


People also ask

How do I enable proxy in Python?

To use a proxy in Python, first import the requests package. Next create a proxies dictionary that defines the HTTP and HTTPS connections. This variable should be a dictionary that maps a protocol to the proxy URL. Additionally, make a url variable set to the webpage you're scraping from.


2 Answers

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") 
like image 126
Ivan Avatar answered Sep 20 '22 19:09

Ivan


Its working for me...

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=http://%s' % PROXY)  chrome = webdriver.Chrome(chrome_options=chrome_options) chrome.get("http://whatismyipaddress.com") 
like image 21
arun Avatar answered Sep 20 '22 19:09

arun