硒Web驱动程序代理身份验证问题

时间:2020-09-10 02:21:03

标签: python-3.x selenium-webdriver proxy-authentication seleniumwire

我尝试使用以下代码从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/")

任何帮助,高度赞赏!

0 个答案:

没有答案