Skip to content
ProxyHub
All guides

Browser automation

Use the proxy with Selenium (Python)

Chrome doesn't accept a username and password in the proxy address. With recent Selenium 4 releases authentication is handled through WebDriver BiDi, with no extensions or third-party libraries.

Step by step

  1. 1

    Update Selenium to the latest version: pip install -U selenium.

  2. 2

    Set the proxy protocol to HTTP in the client area.

  3. 3

    Add --proxy-server=http://HOST:PORT to the Chrome options and enable BiDi with options.enable_bidi = True.

  4. 4

    Register the username and password with driver.network.add_auth_handler() before opening pages.

  5. 5

    For a new IP, call the rotation link and wait about 20 seconds before the next request.

Python
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=http://HOST:PORT")
options.enable_bidi = True

driver = webdriver.Chrome(options=options)
driver.network.add_auth_handler("USER", "PASSWORD")

driver.get("https://api.ipify.org")
print(driver.find_element("tag name", "body").text)
driver.quit()

Replace USER, PASSWORD, HOST and PORT with your proxy's data (client area › proxy › Connection).

Tips

Don't have a proxy yet?

Choose country, carrier and plan: the proxy activates right away.

See plans

Need a hand?

Dedicated 24/7 support on Telegram helps you set up any tool.

Message us on Telegram

More guides