Without credentials it is one line
If your proxy is allowlisted by IP address rather than by username and password, none of the difficulty applies and plain Selenium is enough. Worth checking whether that route is open to you before reaching for anything heavier.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--proxy-server=gate-eu.proxies.nullvault.shop:80")
driver = webdriver.Chrome(options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.page_source)
driver.quit()With credentials, use Selenium Wire
Selenium Wire runs a local proxy that holds the credentials and forwards traffic upstream, which is the least fragile of the available answers. The alternative is building a Chrome extension at runtime to answer the auth prompt, which works and is considerably more code to maintain.
pip install selenium-wireThen point it upstream
The credentials live in the URL here because you are configuring the local proxy rather than Chrome, and the local proxy has no objection to them.
from seleniumwire import webdriver
PROXY = "http://USERNAME:[email protected]:80"
options = {
"proxy": {
"http": PROXY,
"https": PROXY,
"no_proxy": "localhost,127.0.0.1",
}
}
driver = webdriver.Chrome(seleniumwire_options=options)
driver.get("https://api.ipify.org?format=json")
print(driver.page_source)
driver.quit()Consider whether you need a browser at all
A browser is the most expensive way to fetch a page, both in traffic and in the effort of setups like this one. If the content you want is in the HTML rather than assembled by scripts, an ordinary HTTP client does the same job for a fraction of the traffic and none of the authentication trouble.
# If this returns what you need, you did not need Selenium.
import requests
PROXY = "http://USERNAME:[email protected]:80"
r = requests.get(TARGET, proxies={"http": PROXY, "https": PROXY}, timeout=30)What to buy
Residential sticky if the site is guarded enough to need a real browser, since anything that forces you into Selenium is usually looking closely. If it is not guarded, drop the browser and use datacenter per GB with an HTTP client.
Common questions
Why does Chrome ignore my proxy username and password?
Because it does not accept them on the command line at all. The proxy address takes effect and the credentials are dropped, so every request is refused and the setup looks broken rather than unauthenticated. Nothing you write in the argument will change that.
Is Selenium Wire the only option?
No, but it is the least work. The alternative is generating a small Chrome extension at runtime that supplies the credentials when asked. That avoids the dependency and is meaningfully more code to write and keep working.
Does this apply to Firefox too?
Firefox handles it differently and can be configured through its own profile settings, which is why some answers online seem to contradict each other. They are usually describing a different browser than the one you are using.