Chrome 如何使用Socks5代理启动Selenium,该代理使用登录名和密码连接

zaqlnxep  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(302)

我需要使用socks 5代理运行Selenium Webdriver,该代理具有用户名和密码。
我试图在Selenium中使用内置解决方案,但它不使用我的代理(我在whatsmyip网站上检查它)。

proxy = Proxy()
proxy.proxy_type = ProxyType.MANUAL
proxy.socks_proxy = "socks5://1.2.3.4:59101"
proxy.socks_username = "username"
proxy.socks_password = "password"
proxy.socks_version = 5

desired_capabilities = webdriver.DesiredCapabilities.CHROME.copy()
proxy.add_to_capabilities(desired_capabilities)

options = webdriver.ChromeOptions()

driver = webdriver.Chrome(
    executable_path="C:\\Users\\User\\Downloads\\chromedriver-win64\\chromedriver.exe",
    options=options,
    desired_capabilities=desired_capabilities,
)

已经尝试使用selenium-ware和其他解决方案从chatgpt和谷歌,没有工作改变url到socks 5://用户名:email protected(https://stackoverflow.com/cdn-cgi/l/email-protection):59101也不工作

ggazkfy8

ggazkfy81#

对于带auth的socks5代理,可以使用https://github.com/seleniumbase/SeleniumBase
pip install seleniumbase,并在设置变量后使用python运行以下命令:

from seleniumbase import SB

with SB(proxy="USER:PASS@socks5://IP:PORT") as sb:
    sb.driver.get("https://whatismyip.com")
    sb.sleep(6)

相关问题