简体   繁体   English

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

[英]How to set luminati proxy on Selenium Webdriver for chrome in python?

I want to set luminati proxy in webdriver.Chrome for selenium python.我想在 webdriver.Chrome 中为 selenium python 设置luminati代理。 I have tried using this following command:我尝试使用以下命令:

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)

I used my Luminati username,zone and password to setup this.我使用我的Luminati用户名、区域和密码来设置它。 But it's not working.但它不起作用。

Try this code snippet:试试这个代码片段:

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)

from official resource .来自官方资源

Try this code snippet.试试这个代码片段。 It's work for me with Chrome, but you can replace Chrome by Firefox : Chrome 对我有用,但你可以用 Firefox 替换 Chrome:

from selenium.webdriver.chrome.options import Options
from seleniumwire import webdriver
import time


PATH = "path to driver"

options = {
    'proxy': 
    {
        'http': 'http://lum-customer-CUST_ID-zone-ZONE_NAME-country-COUNTRY_TARGET:PASSWORD@zproxy.lum-superproxy.io:22225',
        'https': 'https://lum-customer-CUST_ID-zone-ZONE_NAME-country-COUNTRY_TARGET:PASSWORD@zproxy.lum-superproxy.io:22225'
    },
}


driver = webdriver.Chrome(PATH, seleniumwire_options=options)
# If need to add headers to request
# driver.header_overrides = {

# }
driver.get("https://lumtest.com/myip.json")

print(driver.execute_script('return document.body.innerHTML;')) #print page html
time.sleep(3)


driver.quit()

Likely it's not working because you haven't removed setting of the proxy.no_proxy = 'localhost' , that value shall be excluded.可能它不起作用,因为您尚未删除proxy.no_proxy = 'localhost' ,应排除该值。

If you haven't used Python Selenium Luminati Proxy Desired Capabilities that link before it will be useful ...如果您还没有使用过Python Selenium Luminati Proxy Desired Capabilities之前链接它会很有用...

String proxi = "--your proxy url and port";// like 12345:1212
    Proxy proxy = new Proxy();
    proxy.setHttpProxy(proxi);
    
    //limunati customer info
    proxy.setSocksUsername("Your Username");
    proxy.setSocksPassword("Your Password");
    ChromeOptions options = new ChromeOptions();
    options.setCapability("proxy", proxy);
        
    System.setProperty("webdriver.chrome.driver", "Drivers/chromedriver.exe");
    driver = new ChromeDriver(options);
    
    driver.get("https://www.google.com");

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

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