2

How do I use a proxy IP with selenium chrome?

I've replicated the steps in this question and this question but cannot get chrome to use a new proxy.

To replicate, choose any of the free IPs from this site then execute:

PROXY = "80.237.6.1:34880"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)

chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("https://www.whatismyip.com/my-ip-information/")

When chrome opens the wahtismyip.com page, the displayed IP is my own, not the proxy.

user2723494
  • 1,168
  • 2
  • 15
  • 26

1 Answers1

-2

You have to set the capabilities and force it to use a manual proxy. Username and password are optional. PROXY should be in the form of 'http://68.251.250.193:8080'

proxy = {'address': PROXY,
     'username': 'USERNAME',
     'password': 'PASSWORD'}

capabilities = dict()
capabilities['proxy'] = {'proxyType': 'MANUAL',
                         'httpProxy': proxy['address'],
                         'ftpProxy': proxy['address'],
                         'sslProxy': proxy['address'],
                         'noProxy': '',
                         'class': "org.openqa.selenium.Proxy",
                         'autodetect': False,
                         'socksUsername': proxy['username'],
                         'socksPassword': proxy['password']}


chrome = webdriver.Chrome(executable_path = 'C:\\Users\\whereveryourpathtochromedriveris',
                          chrome_options=chrome_options,
                          desired_capabilities=capabilities)
chrome.get("https://www.whatismyip.com/my-ip-information/")
user2723494
  • 1,168
  • 2
  • 15
  • 26