<p>最后,我自己找到了解决办法,然后我把它推给需要它的兄弟们:</p>
<p>从geckodriver v0.19.1中,他们删除了socketUsername和socketPassword。因此我们不能再使用“<a href="http://username-sessionid-:passwords@zproxy.luminati.io:port" rel="nofollow noreferrer">http://username-sessionid-:passwords@zproxy.luminati.io:port</a>”。在</p>
<p>解决方案是:将用户名和密码保存到firefox配置文件并检索它。
或者我们可以在firefox要求输入密码和用户名时输入如下:</p>
<p>SeleniumWebDriver类:</p>
<pre><code># Set proxy url and proxy port via proxy_url
def get_proxy_cabability(proxy_url):
desired_capability = webdriver.DesiredCapabilities.FIREFOX
desired_capability['proxy'] = {
"proxyType": "manual",
"httpProxy": proxy_url,
"ftpProxy": proxy_url,
"sslProxy": proxy_url,
"socksVersion": 4
}
return desired_capability
#get driver
def get_driver(proxy_url):
desired_capability = self.get_proxy_cabability(proxy_url)
driver = webdriver.Firefox(capabilities=desired_capability, log_path=log_path)
return driver
def set_auth_proxy(username, password):
try:
# Force driver show authentication dialog
self.driver.get('http://www.google.com/')
# Waiting for alert
WebDriverWait(self.driver, 20).until(
ec.alert_is_present())
alert = self.driver.switch_to_alert()
# send auth information
alert.send_keys(username + Keys.TAB + password)
time.sleep(3)
alert.accept()
except Exception as e:
raise Exception("Can not authenticate proxy server")
</code></pre>