相关疑难解决方法(0)

如何在selenium chromedriver中使用经过验证的代理?

搜索了好几个小时后,我开始认为这是不可能的.

我需要为每次运行使用不同的经过身份验证的(非公开的)代理来运行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)

事实上,我已经广泛搜索并且没有找到解决方案,这让我相信没有一个可能存在.

我找到了这个,但我无法理解它:

selenium chromedriver认证代理

不知道是什么browswermob-proxy或应该做什么或如何在Python中实现和测试.除非绝对必要,否则我讨厌堆积创可贴解决方案.

python selenium google-chrome selenium-chromedriver

20
推荐指数
2
解决办法
1万
查看次数