无法为Selenium会话设置代理



尝试使用以下代码设置代理:

from selenium.webdriver.common.proxy import Proxy, ProxyType
prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = "1.10.186.114:46863"
prox.socks_proxy = "1.10.186.114:46863"
prox.ssl_proxy = "1.10.186.114:46863"
capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)
driver = webdriver.Chrome(desired_capabilities=capabilities)

我不断在driver = webdriver.Chrome(desired_capabilities=capabilities)行抛出一个异常。例外情况提到Message: invalid argument: cannot parse capability: proxy from invalid argument: Specifying 'socksProxy' requires an integer for 'socksVersion'

我试图使用的代理只是在网上找到的一个免费代理,有人知道如何解决这个问题吗?

提前谢谢。

更新已解决:

PROXY ="INPUT YOUR PROXY HERE, FOLLOWED BY PORT NUMBER" #KEY HERE IS THAT YOU ENSURE TO SPECIFY 'http=' or 'socks4/socks5=' DEPENDING ON YOUR PROXY
print(PROXY)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(options=chrome_options)
chrome.get("http://whatismyipaddress.com")
time.sleep(3)

相关内容

  • 没有找到相关文章

最新更新