Python Selenium-PhantomJS的Https问题和Firefox的代理身份验证
好的,我的目标是通过代理连接到https网站,该代理需要身份验证,而无需任何人工交互 解决方案#1:FirefoxPython Selenium-PhantomJS的Https问题和Firefox的代理身份验证,python,selenium,proxy,automation,phantomjs,Python,Selenium,Proxy,Automation,Phantomjs,好的,我的目标是通过代理连接到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.F
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',
]