如何在Selenium Webdriver上为python中的chrome设置luminati代理?

Bir*_*ose 5 python selenium automation webdriver python-2.7

我想在 webdriver.Chrome 中为 selenium python设置luminati代理。我尝试使用以下命令:

from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.proxy import *

PROXY = '127.0.0.1:24000'

proxy = Proxy()
proxy.http_proxy = PROXY
proxy.ftp_proxy = PROXY
proxy.sslProxy = PROXY
proxy.no_proxy = "localhost" #etc... ;)
proxy.proxy_type = ProxyType.MANUAL

#limunati customer info
proxy.socksUsername = 'lum-customer-XXXX-zone-XXXX'
proxy.socksPassword = "XXXX"

capabilities = webdriver.DesiredCapabilities.CHROME

proxy.add_to_capabilities(capabilities)

driver = webdriver.Chrome(desired_capabilities=capabilities)
Run Code Online (Sandbox Code Playgroud)

我使用我的Luminati用户名、区域和密码来设置它。但它不起作用。

And*_*kov 1

试试这个代码片段:

from selenium import webdriver

# http://username:password@localhost:8080
PROXY = "http://lum-customer-XXXX-zone-XXXX:XXXX@localhost:8080"

# Create a copy of desired capabilities object.
desired_capabilities = webdriver.DesiredCapabilities.CHROME.copy()
# Change the proxy properties of that copy.
desired_capabilities['proxy'] = {
    "httpProxy":PROXY,
    "ftpProxy":PROXY,
    "sslProxy":PROXY,
    "noProxy":None,
    "proxyType":"MANUAL",
    "class":"org.openqa.selenium.Proxy",
    "autodetect":False
}

# you have to use remote, otherwise you'll have to code it yourself in python to 
# dynamically changing the system proxy preferences
driver = webdriver.Remote("http://localhost:4444/wd/hub", desired_capabilities)
Run Code Online (Sandbox Code Playgroud)

来自官方资源