我如何在python webdriver中设置chrome的代理 [英] how do i set proxy for chrome in python webdriver
本文介绍了我如何在python webdriver中设置chrome的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ b
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, )
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile = profile)
在python webdriver中为FF设置代理。这适用于FF。如何在Chrome中设置这样的代理?我发现这个 exmaple ,但不是很有帮助。当我运行脚本没有任何反应(Chrome浏览器未启动)。
解决方案
from selenium import webdriver
PROXY =23.23 .23.23:3128#IP:PORT或HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(' - proxy-server =%s'%PROXY)
chrome = webdriver.Chrome(chrome_options = chrome_options)
chrome.get(http://whatismyipaddress.com)
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).
解决方案
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(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")
这篇关于我如何在python webdriver中设置chrome的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文