gpt4 book ai didi

Python Selenium Webdriver - 代理身份验证

转载 作者:太空狗 更新时间:2023-10-29 21:12:13 24 4
gpt4 key购买 nike

我想将 Selenium Webdriver 与需要用户身份验证的代理一起使用。这可能吗?

这是我到目前为止所拥有的,但我不知道将凭据放在哪里 (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 内置的代理功能。

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 个赞成票。

关于Python Selenium Webdriver - 代理身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19295163/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com