【发布时间】:2016-03-12 10:56:38
【问题描述】:
好的,所以我的目标是通过代理连接到 https 网站,该代理需要身份验证而无需任何人工交互。
解决方案 #1:Firefox
fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type", 1)
fp.set_preference("network.proxy.http", "IP")
fp.set_preference("network.proxy.http_port", PORT)
driver = webdriver.Firefox(firefox_profile=fp)
driver.get("http://www.google.com")
问题:一旦浏览器打开,它会打开用户名和密码的身份验证弹出窗口。
alert = driver.switch_to_alert()
alert.send_keys('balbla')
不起作用,根本没有反应。 将代理更改为也没有运气
http://username:password@ip
解决方案 #2:PhantomJs
使用 phantomjs 我设法在代码中进行身份验证:
service_args = [
'--proxy=https://IP:PORT',
'--proxy-type=http',
'--proxy-auth=USERNAME:PASSWORD',
]
br = webdriver.PhantomJS(PATH,service_args=service_args)
br.get('https://www.google.com/')
问题:我无法浏览任何 https 网站,例如我正在尝试进入 https://www .gmail.com,我得到空白页面。 代理肯定在使用 https(手动加倍检查)。
添加
'--ssl-protocol=any'
效果不佳。
我在 Linux 环境下使用 selenium 和 python。寻找任何可以帮助我解决问题的解决方案。
谢谢。
【问题讨论】:
标签: python selenium proxy automation phantomjs