Oxylabs’ Residential Proxies integration with Selenium

Requirements

For the integration to work, you’ll need to install Selenium on your system. You can do it using pip command:

pip install selenium

Another required package is webdriver-manager. It’s a package that simplifies the management of binary drivers for different browsers, so you don’t need to manually download a new version of a web driver after each update. Visit the official project directory on pypi to find out more information. You can install the following using pip as well.

pip install webdriver-manager

Required version of Python: Python 3.5 (or higher)

Proxy Authentication

For proxies to work, you’ll need to specify your account credentials inside the main.py file.

USERNAME = "your_username"
PASSWORD = "your_password"
HOST = "pr.oxylabs.io"
PORT = 7777

Adjust the your_username and your_password fields with the username and password of your Oxylabs account.

Country-Specific Entry Node

If you want, you can also specify the entry node of a specific country:

COUNTRY = "US"

To do that, adjust the country variable to any country that Oxylabs support.
You can check out our documentation for a complete list of country-specific entry nodes.

Testing Proxy Connection

To see if the proxy is working, try visiting ip.oxylabs.io.
If everything is working correctly, it will return an IP address of a proxy that you’re using.

try:
    driver.get("https://ip.oxylabs.io/")
    time.sleep(5)
finally:
    driver.close()

Full Code

import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from proxies import chrome_proxy

USERNAME = "your_username"
PASSWORD = "your_password"
HOST = "pr.oxylabs.io"
PORT = 7777
COUNTRY = "US"

options = webdriver.ChromeOptions()
proxy_ext = chrome_proxy(USERNAME, PASSWORD, HOST, PORT, COUNTRY)
options.add_extension(proxy_ext)
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)

try:
    driver.get("https://ip.oxylabs.io/")
    time.sleep(5)
finally:
    driver.close()

If you’re having any trouble integrating proxies with Selenium and this guide didn’t help you – feel free to contact Oxylabs customer support at [email protected].

GitHub

https://github.com/oxylabs/selenium-proxy-integration