gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:00:02 25 4
gpt4 key购买 nike

我想在 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)

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

最佳答案

试试这个代码片段:

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)

来自官方resource .

关于python - 如何在 python 中为 chrome 的 Selenium Webdriver 设置 luminati 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51817104/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com