# The proxy has your machine's IP on its whitelist, so no credentials
# are sent: Chrome ignores them in --proxy-server anyway.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless=new") # remove to watch the browser
options.add_argument("--proxy-server=http://HOST:PORT")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com/")
print(driver.title)
finally:
driver.quit()
# Selenium 4.51+ with WebDriver BiDi; pip install selenium
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
options = webdriver.FirefoxOptions()
options.enable_bidi = True
options.add_argument("-headless") # remove to watch the browser
options.proxy = Proxy({
"proxyType": ProxyType.MANUAL,
"httpProxy": "HOST:PORT",
"sslProxy": "HOST:PORT",
})
driver = webdriver.Firefox(options=options)
try:
# Answers the proxy's 407 with your username and password
driver.network.add_authentication_handler(
lambda request: request.provide_credentials("USERNAME", "PASSWORD")
)
driver.get("https://example.com/")
print(driver.title)
finally:
driver.quit()
# The proxy has your machine's IP on its whitelist, so no credentials
# are sent. For a password instead, see selenium-firefox-auth.
from selenium import webdriver
from selenium.webdriver.common.proxy import Proxy, ProxyType
options = webdriver.FirefoxOptions()
options.add_argument("-headless") # remove to watch the browser
options.proxy = Proxy({
"proxyType": ProxyType.MANUAL,
"httpProxy": "HOST:PORT",
"sslProxy": "HOST:PORT",
})
driver = webdriver.Firefox(options=options)
try:
driver.get("https://example.com/")
print(driver.title)
finally:
driver.quit()
# Switch the proxy to SOCKS5 first, then use the port the order shows.
# The whitelist applies to SOCKS5 as well, so no credentials here either.
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("--headless=new") # remove to watch the browser
options.add_argument("--proxy-server=socks5://HOST:PORT")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://example.com/")
print(driver.title)
finally:
driver.quit()
# Put the public IPv4 address your code runs from on the proxy's
# whitelist. Replaces the list; an empty list turns whitelisting off
# and the proxy falls back to username and password.
curl -X PUT "https://api.proxyjam.com/public/v1/orders/ORDER_ID/whitelist" \
-H "X-API-Key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"whitelisted_ips": ["YOUR_IP"]}'