好的,所以我的目标是通过代理连接到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。寻找任何能帮助我解决问题的解决方案。
谢谢一个头。
我想这有点晚了:)-但基本上从代理中删除https,并将代理类型设置为https,即:
service_args = [
'--proxy=IP:PORT',
'--proxy-type=https',
'--proxy-auth=USERNAME:PASSWORD',
]