硒:通过具有用户名/密码的代理连接-如何?

时间:2019-06-29 15:22:37

标签: python selenium selenium-webdriver proxy

这个完全相同的问题有很多,但是所有答案都已过时,例如:

这是2016年的过时答案: Selenium using Python: enter/provide http proxy password for firefox 还有2017年的另一个过时的答案: Selenium using Python: enter/provide http proxy password for firefox

无论如何,当我尝试使用需要用户名和密码的代理服务器时,如下所示:

from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_preference("network.proxy.type", 1)
profile.set_preference("network.proxy.http", PROXY_HOST)
profile.set_preference("network.proxy.http_port", PROXY_PORT)
profile.set_preference("network.proxy.socks_username", USERNAME)
profile.set_preference("network.proxy.socks_password", PASSWORD)
profile.set_preference('network.proxy.ssl', PROXY_HOST)
profile.set_preference('network.proxy.ssl_port', PROXY_PORT)

profile.update_preferences()

# executable_path  = define the path if u don't already have in the PATH system variable. 

driver = webdriver.Firefox(firefox_profile=profile)
page = driver.get('http://whatismyipaddress.com/')

这根本不起作用。

目前通过代理(同时提供用户名和密码)进行连接的最干净的方法是什么?

(如果您能解释为什么我的代码不起作用-事实不起作用对我来说毫无意义!)

0 个答案:

没有答案