2013-10-10 95 views
5

我想將Selenium Webdriver與需要用戶身份驗證的代理一起使用。這可能嗎?Python Selenium Webdriver - 代理身份驗證

這是,我有這麼遠,但我不知道放在哪裏憑據(用戶名:@通代理:端口)

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 
+0

你有沒有找到解決方案? – ChairmanMeow

+0

嗨,是的,我最終與Selenium一起使用了PhanomJS:https://realpython.com/blog/python/headless-selenium-testing-with-python-and-phantomjs/和http://phantomjs.org/api/command -line.html – Maecky

+0

以擴展名使用Firefox,請參閱:https://stackoverflow.com/a/39903614/955422 –

回答

-1

這是我一直使用的是什麼沒有任何問題,使用內置代理功能的Selenium。

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) 
相關問題