ryy77
ryy77

Reputation: 1294

How to set proxies for chrome webdriver version 2.36?(python)

I've made a chrome webdriver python program and I'm trying to set the proxies. I've got this error:

This site can’t be reached The webpage at https://www.amazon.com/Nokia-Body-Composition-Wi-Fi-Scale/dp/B071XW4C5Q/ref=sr_1_1/138-3260504-2979110?s=bedbath&ie=UTF8&qid=1520585204&sr=1-1&keywords=-sdfg might be temporarily down or it may have moved permanently to a new web address. ERR_NO_SUPPORTED_PROXIES

For this program I used version 2.36 so I think will be different. Today I have to switch to this version because the previous version has some problem with send_keys method. I attached the code. I will appreciate any help.

from selenium import webdriver

# set the proxies to hide actual IP

proxies = {
    'http': 'http://210.213.90.61:80',
    'https': 'https://27.111.43.178:8080'
}

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % proxies)

driver = webdriver.Chrome(executable_path="C:\\Users\Andrei\Downloads\webdriver2\chromedriver.exe",
                          chrome_options=chrome_options)

driver.get('https://www.amazon.com/Nokia-Body-Composition-Wi-Fi-Scale/dp/B071XW4C5Q/ref=sr_1_1/138-3260504-2979110?s=bedbath&ie=UTF8&qid=1520585204&sr=1-1&keywords=-sdfg')

Upvotes: 2

Views: 922

Answers (1)

Will Keeling
Will Keeling

Reputation: 22994

According to the google-chrome man page, the proxies should be specified like this:

--proxy-server="https=proxy1:80;http=socks4://baz:1080"

So I think what you want is:

proxy_arg = ';'.join('%s=%s' % (k, v) for k, v in proxies.items())
chrome_options.add_argument('--proxy-server="%s"' % proxy_arg)

The description from the man page says:

It is also possible to specify a separate proxy server for different URL types, by prefixing the proxy server specifier with a URL specifier:

Example:

 --proxy-server="https=proxy1:80;http=socks4://baz:1080"
     Load https://* URLs using the HTTP proxy "proxy1:80". And load http://*
     URLs using the SOCKS v4 proxy "baz:1080".

Upvotes: 4

Related Questions