[英]Python selenium chromedriver authenticate luminati proxy?
Hi I am using selenium chromedriver and using luminati proxy with it.嗨,我正在使用 selenium chromedriver 并使用 luminati 代理。 But I cant figure out how to set proxy username and password.
但我不知道如何设置代理用户名和密码。
I have tried this code:我试过这段代码:
import random
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.proxy import Proxy, ProxyType, ProxyTypeFactory
from selenium.webdriver.support import expected_conditions as EC
username = 'lum-customer-XXXX-static'
password = 'XXXXXX'
port = 22225
session_id = random.random()
super_proxy_url = ('http://%s-session-%s:%s@zproxy.lum-superproxy.io:%d' %(username, session_id, password, port))
proxy = Proxy()
proxy.http_proxy = proxy_url
proxy.ftp_proxy = proxy_url
proxy.ssl_proxy = proxy_url
proxy.no_proxy = "localhost"
proxy.proxy_type = ProxyType.MANUAL
chromedriver_path = '/usr/local/share/chromedriver' # Change this to your own chromedriver path!
driver = webdriver.Chrome(executable_path=chromedriver_path,chrome_options=chrome_options)
driver.get("https://whatismyipaddress.com/")
But Is not connecting to my the proxy server.但是没有连接到我的代理服务器。 I have also tried desired_capabilities.
我也尝试过desired_capabilities。 Its code is shown as below.
其代码如下所示。
desired_capabilities = webdriver.DesiredCapabilities.CHROME
desired_capabilities['proxy'] = {
"proxyType":"manual",
"httpProxy":"zproxy.lum-superproxy.io:22225",
"ftpProxy":"zproxy.lum-superproxy.io:22225",
"sslProxy":"zproxy.lum-superproxy.io:22225",
"socksUsername":"lum-customer-XXXXX-zone-static",
"socksPassword":"XXXX",
"socksVersion": 4
}
driver = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,desired_capabilities=desired_capabilities)
driver.get("https://whatismyipaddress.com/")
WebDriverWait(driver, 20).until(EC.alert_is_present())
alert = driver.switch_to_alert()
alert.send_keys(username + Keys.TAB + password)
# time.sleep(5)
alert.accept()
But the username and password is not filling in the alert box that requires username and password for the proxy.但是用户名和密码没有填写代理需要用户名和密码的警告框。
Please help me.请帮我。 If there is any alternate way to authenticate the proxy then please share with me.
如果有任何替代方法来验证代理,请与我分享。 Thanks
谢谢
Using proxy authentication with selenium can be tricky because you need to use the right versions of webdriver, selenium and browser to all support using a proxy.对 selenium 使用代理身份验证可能会很棘手,因为您需要使用正确版本的 webdriver、selenium 和浏览器才能全部支持使用代理。 My recommendation is to use one of these alternatives to setting the proxy directly in your code using selenium.
我的建议是使用其中一种替代方法来使用 selenium 在您的代码中直接设置代理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.