嗨,我正在使用 selenium chromedriver 并使用 luminati 代理。但我不知道如何设置代理用户名和密码。
我试过这段代码:
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/")
但是没有连接到我的代理服务器。我也尝试过desired_capabilities。其代码如下所示。
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()
但是用户名和密码没有填写代理需要用户名和密码的警告框。
请帮我。如果有任何替代方法来验证代理,请与我分享。谢谢