簡體   English   中英

Python Selenium Webdriver - 代理身份驗證

[英]Python Selenium Webdriver - Proxy Authentication

我想將 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 票。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM