Python Selenium Webdriver - 代理身份验证 [英] Python Selenium Webdriver - Proxy Authentication
本文介绍了Python Selenium Webdriver - 代理身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将 Selenium Webdriver 与需要用户身份验证的代理一起使用.这可能吗?
I want to use Selenium Webdriver with a proxy which needs user authentication. Is this possible?
这是我到目前为止所拥有的,但我不知道将凭据放在哪里(user:pass@proxy:port)
this is, what i have so far, but I don't know where to put the credentials ( user:pass@proxy:port)
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", "proxy")
profile.set_preference("network.proxy.http_port", "port_number")
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.get('http://www.google.com')
driver.title
推荐答案
这是我一直使用的,没有任何问题,使用 Seleniums 内置代理功能.
This is what I have been using without any issues, using Seleniums built in proxy capabilities.
from selenium import webdriver
from selenium.webdriver.common.proxy import *
prof = webdriver.FirefoxProfile()
prof.set_preference('signon.autologin.proxy', 'true')
prof.set_preference('network.proxy.share_proxy_settings', 'false')
prof.set_preference('network.automatic-ntlm-auth.allow-proxies', 'false')
prof.set_preference('network.auth.use-sspi', 'false')
proxy_data = {'address': '123.123.123.123:2345',
'usernmae': 'johnsmith123',
'password': 'iliketurtles'}
proxy_dict = {'proxyType': ProxyType.MANUAL,
'httpProxy': proxy_data['address'],
'ftpProxy': proxy_data['address'],
'sslProxy': proxy_data['address'],
'noProxy': '',
'socksUsername': proxy_data['username'],
'socksPassword': proxy_data['password']}
proxy_config = Proxy(proxy_dict)
driver = webdriver.Firefox(proxy=proxy_config, firefox_profile=prof)
这个答案来自 2017 年.Selenium 和 Firefox 都进行了重大更改,但不再有效.因此,为什么这个答案从 5 票赞成到现在 -3 票.
this answer was from 2017. Selenium and Firefox have both made major changes and it no longer works. hence why this answer went from 5 upvotes to now -3.
这篇关于Python Selenium Webdriver - 代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文