简体   繁体   中英

Python Selenium Webdriver - Proxy Authentication

I want to use Selenium Webdriver with a proxy which needs user authentication. Is this possible?

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

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)

EDIT: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM