Carlos_OL
Carlos_OL

Reputation: 93

I cannot get my proxies to work on Selenium

I have searched on stackoverflow as well as just googled how to use Proxies with Selenium. I found two different ways but none are working for me. Can you guys please help me figure out what I am doing wrong?

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType

proxy = "YYY.YYY.YYY.YY:XXXX"

prox = Proxy()
prox.proxy_type = ProxyType.MANUAL
prox.http_proxy = proxy
prox.https_proxy = proxy

capabilities = webdriver.DesiredCapabilities.CHROME
prox.add_to_capabilities(capabilities)

options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
driver = webdriver.Chrome(desired_capabilities=capabilities, options=options)

Code Above did not work. The page would open but if I go to "Whatsmyip.com" I could see my home IP.

I then tried another method I found on this link: https://www.browserstack.com/guide/set-proxy-in-selenium

proxy = "YYY.YYY.YYY.YY:XXXX"
options = webdriver.ChromeOptions()
options.add_experimental_option('detach', True)
options.add_argument("--proxy--server=%s" % proxy)
driver = webdriver.Chrome(options = options)

Same result as with the previous method. Browser will open but home IP.

Worth mentioning that I tried with USER:PASS proxies, as well as IP Authorized proxies. None worked!

In addition to helping me figure out how to use proxies, I would also like to understand why these methods are different. On the one hand, the Selenium documentation talks about a proxy class which you access via the "common.proxy" class, yet the second method is directly using Chrome's options and not Selenium's proxy class. I am confused as to why have two methods, and of course which one works more reliably.

Thanks

Upvotes: 1

Views: 211

Answers (0)

Related Questions