2013-10-10 17 views
5

Desidero utilizzare Selenium Webdriver con un proxy che richiede l'autenticazione dell'utente. È possibile?Python Selenium Webdriver - Autenticazione proxy

questo è, quello che ho finora, ma non so dove mettere le credenziali (utente: passaggio @ Proxy: Porta)

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

Hai mai trovato la soluzione? – ChairmanMeow

+0

Ciao, sì ho finito per usare PhanomJS con Selenium: https://realpython.com/blog/python/headless-selenium-testing-with-python-and-phantomjs/ e http://phantomjs.org/api/command -line.html – Maecky

+0

per utilizzare firefox con un'estensione, vedere questo: https://stackoverflow.com/a/39903614/955422 –

risposta

-1

Questo è quello che ho usato senza problemi , usando il Selenium integrato nelle funzionalità proxy.

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) 
Problemi correlati