Issue
I've been trying to use a http proxy with Selenium. What I have so far is:
PROXY = "46.4.29.2:80"
webdriver.DesiredCapabilities.CHROME['proxy'] = {
"httpProxy": PROXY,
"ftpProxy": PROXY,
"sslProxy": PROXY,
"noProxy": None,
"proxyType": "MANUAL",
"class": "org.openqa.selenium.Proxy",
"autodetect": False
}
However, it simply doesn't work and throws:
selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CONNECTION_FAILED
Solution
Personally, I use a library called selenium-wire https://pypi.org/project/selenium-wire/ which can be used for both authenticated and non-authenticated proxies. Here is the documentation reference for proxy use https://github.com/wkeeling/selenium-wire#proxies
I have made a short snippet of code that uses a public proxy to go to google.com
import seleniumwire
from seleniumwire import webdriver
options = {'proxy':
{
'http' : 'http://45.152.188.246:3128'}
}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.get("https://google.com/")
Here is also a method that would work without the need for selenium-wire.
options = webdriver.ChromeOptions()
options.add_argument('--proxy-server=45.152.188.246:3128')
driver = webdriver.Chrome(options=options)
driver.get("https://google.com/")
Answered By - Akdeniz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.