Integrations / Browser automation

Use Proxys with Selenium

Use Proxys with Selenium. Chrome can't take proxy credentials on the command line, so use an allowed IP or selenium-wire.

Steps

  1. Easiest: add your machine's IP under Sub-users > Allowed IPs, then use the gateway with no credentials.
  2. Or install selenium-wire and pass the proxy with credentials.
Python (allowed IP)
from selenium import webdriver

opts = webdriver.ChromeOptions()
opts.add_argument("--proxy-server=http://gw.proxys.co:8000")
driver = webdriver.Chrome(options=opts)
driver.get("https://ipinfo.io/json")
Python (selenium-wire)
from seleniumwire import webdriver

proxy = "http://USERNAME-country-us:PASSWORD@gw.proxys.co:8000"
driver = webdriver.Chrome(seleniumwire_options={"proxy": {"http": proxy, "https": proxy}})

Before you start

Replace USERNAME and PASSWORD with a sub-user's credentials from the dashboard. Change -country-us to the country you need, or remove it for a random location. See targeting options for city, ASN and sticky sessions.

Try 1 GB for $1