standorfall999 standorfall999 - 5 months ago 820
Python Question

python selenium proxys in chrome/phantomjs

I've tried to use proxy s in chrome but,
I get this error.

driver = webdriver.Chrome(proxy=proxy)
TypeError: __init__() got an unexpected keyword argument 'proxy'


This is the code I am trying to use
but it only works with FireFox, so I was wondering if it is possible to do this with phatom JS and chrome

from selenium.webdriver.common.proxy import *
from selenium import webdriver
myProxy = "31.28.244.230:41905"

proxy = Proxy({
'proxyType': ProxyType.MANUAL,
'httpProxy': myProxy,
'ftpProxy': myProxy,
'sslProxy': myProxy,
'noProxy': '' # set this value as desired
})

driver = webdriver.Chrome(proxy=proxy)

driver.get("http://ipchicken.com/")

Answer

Try doing it like this

from selenium import webdriver

PROXY = "23.23.23.23:3128" # IP:PORT or HOST:PORT

chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=http://%s' % PROXY)

chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")