如何解决硒Web驱动程序代理身份验证问题
我尝试使用以下代码从selenium Web驱动程序进行代理身份验证,但未使用凭据。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
USER_AGENT= "Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:64.0) Gecko/20100101 Firefox/72.0"
fp = webdriver.FirefoxProfile()
fp.set_preference("network.proxy.type",1)
fp.set_preference("network.proxy.https",site_url)
fp.set_preference("network.proxy.http",site_url)
fp.set_preference("network.proxy.http_port",int(site_port))
fp.set_preference("network.proxy.https_port",int(site_port))
fp.set_preference("network.proxy.ssl",site_url)
fp.set_preference("network.proxy.ssl_port",int(site_port))
fp.set_preference("network.proxy.ftp",site_url)
fp.set_preference("network.proxy.ftp_port",int(site_port))
fp.set_preference("network.proxy.socks",site_url)
fp.set_preference("network.proxy.socks_port",int(site_port))
fp.set_preference("network.proxy.socks_username",user_id)
fp.set_preference("network.proxy.socks_password",pwd)
fp.set_preference("network.proxy.http_username",user_id)
fp.set_preference("network.proxy.http_password",pwd)
fp.set_preference("network.proxy.httpss_username",user_id)
fp.set_preference("network.proxy.https_password",pwd)
fp.set_preference("network.proxy.ssl_username",user_id)
fp.set_preference("network.proxy.ssl_password",pwd)
fp.set_preference("network.proxy.ftp_username",user_id)
fp.set_preference("network.proxy.ftp_password",pwd)
fp.set_preference("general.useragent.override",USER_AGENT)
fp.update_preferences()
options= Options()
credential=user_id +"u\ue004"+ pwd
browser= webdriver.Firefox(firefox_profile=fp,options= options)
obj = browser.switch_to.alert()
obj.send_keys(keysToSend=credential)
obj.accept()
browser.get("https://www.zillow.com/")
我也尝试过seleniumwire,但是执行脚本3到4次,却遇到类似getaddrinfo失败的错误。
proxy=user_id+':'+pwd+'@'+site_url+':'+site_port
options={
'proxy':{
'http':'http://'+proxy,#'https':'https://'+proxy,'http' : 'socks5://'+proxy,#'no_proxy':'localhost,127.0.0.1,dev_server:8080'
# 'connection_timeout': 10
}
}
browser= webdriver.Firefox(firefox_profile=fp,seleniumwire_options= options)
browser.get("https://www.zillow.com/")
任何帮助,高度赞赏!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。