GBProxies

How to Use Proxies with Selenium

Chrome in Selenium does not accept a username and password in the --proxy-server flag. The simplest way is selenium-wire, which handles the login for you.

Steps

  1. Install selenium-wire with pip install selenium-wire
  2. Pass the proxy URL with username and password in seleniumwire_options
  3. Start the driver and open the target page
  4. Use a session id to keep one IP for the whole test

Example code

from seleniumwire import webdriver

proxy = "http://USERNAME-cc-ca:PASSWORD@gw.gbproxies.cc:10000"
driver = webdriver.Chrome(seleniumwire_options={
    "proxy": {"http": proxy, "https": proxy, "no_proxy": "localhost,127.0.0.1"}
})
driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()

Replace USERNAME and PASSWORD with the proxy login from the Proxies page of the console. Port 10000 is residential HTTP; see the ports of every product below.

Tips

  • Turn off images with Chrome preferences to save GB
  • Run one driver per sticky session

Common questions

Can I use plain Selenium without extra packages?

Chrome needs an extension or selenium-wire for proxy logins; Firefox can read credentials from a profile.

How to Use Proxies with Selenium