简体   繁体   English

Python selenium chromedriver 验证 luminati 代理?

[英]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 在您的代码中直接设置代理。

  1. Set the proxy with credentials on the host machine - just be careful to turn the proxy off when you don't need it or to set it up in a virtual machine that you only use with the proxy.在主机上使用凭据设置代理 - 请注意在不需要代理时将其关闭,或者将其设置在仅与代理一起使用的虚拟机中。 that is how they recommend doing it on the selenium website: https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy这就是他们在 selenium 网站上推荐的方式: https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#using-a-proxy
  2. Use Luminati Proxy manager ( https://github.com/luminati-io/luminati-proxy ) to set up a proxy port that does not require authentication and passes the traffic on with your proxy credentials.使用 Luminati 代理管理器 ( https://github.com/luminati-io/luminati-proxy ) 设置不需要身份验证的代理端口并使用您的代理凭据传递流量。
  3. Use puppeteer to handle headless chrome ( https://pypi.org/project/pyppeteer/ ) as the puppeteer library comes with the right version of chromium and is much easier to get started with.使用 puppeteer 来处理 headless chrome ( https://pypi.org/project/pyppeteer/ ),因为 puppeteer 库带有正确版本的 chromium,并且更容易上手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM