搜索了好几个小时后,我开始认为这是不可能的.
我需要为每次运行使用不同的经过身份验证的(非公开的)代理来运行Chrome.
PROXY_IP = "<some IP address>"
UID = "<the user id>"
PWD = "<the password">
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=%s:%s@%s" % (UID,PWD,PROXY_IP))
driver = webdriver.Chrome(executable_path=".\\driver\\chromedriver.exe",
chrome_options=options)
driver.get("<site URL>")
Run Code Online (Sandbox Code Playgroud)
Chrome会启动并显示错误:
This webpage is not available
ERR_NO_SUPPORTED_PROXIES
Run Code Online (Sandbox Code Playgroud)
如果我使用公共代理不需要像这样的身份验证...
PROXY_IP = "<public proxy IP address>"
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=%s" % PROXY_IP)
driver = webdriver.Chrome(executable_path=".\\driver\\chromedriver.exe",
chrome_options=options)
driver.get("<site URL>")
Run Code Online (Sandbox Code Playgroud)
...它运行得很好,并在使用代理时显示网站.
我还在http://
用户ID前面尝试了一个变体:
options.add_argument("--proxy-server=http://%s:%s@%s" % (UID,PWD,PROXY_IP))
Run Code Online (Sandbox Code Playgroud)
事实上,我已经广泛搜索并且没有找到解决方案,这让我相信没有一个可能存在.
我找到了这个,但我无法理解它:
不知道是什么browswermob-proxy
或应该做什么或如何在Python中实现和测试.除非绝对必要,否则我讨厌堆积创可贴解决方案.
我在Python 2.7中使用Firefox WebDriver和Selenium.当我运行程序时,我的python程序启动Firefox浏览器并访问不同的网站.但是,我需要使用身份验证设置代理,这样当程序访问任何网站时,它将通过代理服务器访问.
SO上有一些类似的问题.但是,没有针对Selenium Firefox WebDriver的Python的特定解决方案.