简体   繁体   中英

Unable to set a proxy for Selenium session

Trying to set a proxy using the following code:

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)

I keep getting an exception thrown at the line driver = webdriver.Chrome(desired_capabilities=capabilities) . The exception mentions Message: invalid argument: cannot parse capability: proxy from invalid argument: Specifying 'socksProxy' requires an integer for 'socksVersion'

The proxy I am trying to use was just a free one found online, does anyone have any ideas how to solve this?

Thanks in advance.

Update solved:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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