Skyhorse_tamer
Skyhorse_tamer•4w ago

selenium + Residential Proxies

Hi all, I am rather stupid and need some help setting chrome_options in the Selenium Init to use residential proxies? I've tested a few ways and chrome seems to ignore the proxy and use the host server ip. Essentially i just do this: def init(self, args, **kwargs) -> None: super().init(args, kwargs) self.driver = self._init_driver() . . . def _init_driver(self): chrome_options = Options() arguments = [ "--headless=new", "--no-sandbox", "--disable-dev-shm-usage", "--disable-gpu", ] for arg in arguments: chrome_options.add_argument(arg) proxy = { "host": "proxy.apify.com", "port": "8000", "username": "groups-RESIDENTIAL", "password": "<>" }
add_proxy(chrome_options, proxy=Proxy(
proxy)) chrome_options.binary_location = "/usr/bin/google-chrome-stable" driver = webdriver.Chrome(options=chrome_options) return driver
1 Reply
Matous
Matous•3w ago
Hey there, I have slightly modified python-selenium template for Apify Actor:
proxy_configuration = await Actor.create_proxy_configuration(
groups=['RESIDENTIAL'],
country_code='US',
)
proxy_url = await proxy_configuration.new_url()
seleniumwire_options = {
'proxy': {
'http': proxy_url,
'https': proxy_url,
# 'no_proxy': 'localhost,127.0.0.1' # optionally bypass proxy
}
}

driver = webdriver.Chrome(options=chrome_options, seleniumwire_options=seleniumwire_options)
proxy_configuration = await Actor.create_proxy_configuration(
groups=['RESIDENTIAL'],
country_code='US',
)
proxy_url = await proxy_configuration.new_url()
seleniumwire_options = {
'proxy': {
'http': proxy_url,
'https': proxy_url,
# 'no_proxy': 'localhost,127.0.0.1' # optionally bypass proxy
}
}

driver = webdriver.Chrome(options=chrome_options, seleniumwire_options=seleniumwire_options)
Note that you have to install additional packages (selenium-wire + deps). Please let me know if that solves your problem. PS: I have asked the tooling team to add some examples to the python-templates so the next time you might find it there 😉

Did you find this page helpful?