Integrations · Automation & scraping
Use HProxy with Selenium.
Drive a real browser through an authenticated HProxy proxy with Selenium.
Selenium automates a real browser, the tool of choice when a site only yields to something that renders JavaScript and behaves like a person.
A headful browser is convincing until every session comes from the same IP. A residential exit per session is what lets Selenium scale past a handful of runs before a site starts challenging it.
Setting up HProxy in Selenium
- 1.Install Selenium Wire (pip install selenium-wire), which adds the authenticated-proxy support vanilla Selenium lacks.
- 2.Put your host, port and login in the seleniumwire_options proxy config.
- 3.Launch the driver as usual; every request the browser makes now exits through the proxy.
from seleniumwire import webdriver
opts = {"proxy": {
"http": "http://user-country-us:pass@res.hproxy.com:8080",
"https": "http://user-country-us:pass@res.hproxy.com:8080",
}}
driver = webdriver.Chrome(seleniumwire_options=opts)
driver.get("https://ipinfo.io/json")Worth knowing
Vanilla Selenium cannot pass a proxy username and password; Selenium Wire is the standard way around it.
Frequently asked questions
Why does Selenium ignore my proxy username and password?
Because vanilla Selenium cannot send proxy credentials at all. The proxy-server flag it passes to the browser accepts a host and port and has no field for authentication, so an authenticated proxy simply fails. Selenium Wire is the standard way around it, which is why the example above uses it rather than plain Selenium.
Can I use IP whitelisting instead of Selenium Wire?
Yes, and on a fixed server it is the simpler answer. Whitelist the machine's address with your provider and the proxy accepts the connection without credentials, which means plain Selenium works with just the host and port. It stops working the moment that machine's address changes.
Does Selenium leak my real IP through WebRTC?
It can, because it drives a real browser and WebRTC discovers your address outside the proxied path entirely. The proxy is not failing; it was never in a position to see that traffic. Disable or restrict WebRTC in the browser options if the exit address is the identity that matters.
How do I rotate IPs between Selenium sessions?
Start a new driver with fresh credentials rather than trying to change the proxy on a running one. With a rotating proxy you get a different exit automatically; with a sticky session request a new session identifier. Reusing one driver keeps the same browser profile too, which defeats the rotation anyway.
The host, port and login shown here are the format; your exact values are on your dashboard, ready to copy.