Selenium
This guide provides instructions on how to integrate Evomi’s proxies with Selenium, a popular web browser automation tool.
Prerequisites
Before you begin, ensure you have the following:
- Python installed on your system
- Selenium installed in your project
- Your Evomi proxy credentials (username and password)
Installation
If you haven’t already installed Selenium, you can do so using pip:
pip install selenium
You’ll also need to install a WebDriver for your preferred browser. For this guide, we’ll use ChromeDriver:
- Download ChromeDriver from the official website.
- Add the ChromeDriver executable to your system PATH.
Configuration
To use Evomi proxies with Selenium, you need to configure the WebDriver with the proxy settings. Here’s how you can do it:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Proxy configuration
proxy_host = "rp.evomi.com"
proxy_port = "1000"
proxy_username = "your_username"
proxy_password = "your_password_session-anychars_mode-speed"
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument(f'--proxy-server={proxy_host}:{proxy_port}')
# Create a new Chrome driver instance
driver = webdriver.Chrome(options=chrome_options)
# Set up authentication
driver.get("https://" + proxy_host)
driver.execute_script(f"""
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://{proxy_host}', true);
xhr.setRequestHeader('Proxy-Authorization', 'Basic ' + btoa('{proxy_username}:{proxy_password}'));
xhr.send();
""")
# Navigate to a page to test the proxy
driver.get("https://ip.evomi.com/s")
print(driver.page_source)
# Close the browser
driver.quit()
Replace your_username
with your actual Evomi proxy username.
Explanation
Let’s break down the key parts of this script:
- We import the necessary modules from Selenium.
- We set up the proxy configuration with the Evomi proxy details.
- We create Chrome options and add the proxy server argument.
- We create a new Chrome WebDriver instance with these options.
- We set up proxy authentication using JavaScript injection.
- We navigate to
https://ip.evomi.com/s
to verify the proxy connection. - We print the page source, which should show the IP address of the proxy you’re using.
- Finally, we close the browser.
Evomi Proxy Endpoints
Depending on the Evomi product you’re using, you’ll need to adjust the proxy host and port in your code. Here are the endpoints for different Evomi products:
Residential Proxies
- HTTP Proxy: rp.evomi.com:1000
- HTTPs Proxy: rp.evomi.com:1001
- SOCKS5 Proxy: rp.evomi.com:1002
Mobile Proxies
- HTTP Proxy: mp.evomi.com:3000
- HTTPs Proxy: mp.evomi.com:3001
- SOCKS5 Proxy: mp.evomi.com:3002
Datacenter Proxies
- HTTP Proxy: dcp.evomi.com:2000
- HTTPs Proxy: dcp.evomi.com:2001
- SOCKS5 Proxy: dcp.evomi.com:2002
To use a different product or protocol, simply replace the proxy_host
and proxy_port
variables in your code with the appropriate endpoint and port from the list above.
Running the Script
Save the script to a file (e.g., selenium_proxy_test.py
) and run it using Python:
python selenium_proxy_test.py
If everything is set up correctly, you should see the content of https://ip.evomi.com/s
printed in your console, showing the IP address of the Evomi proxy you’re using.
Tips and Troubleshooting
- If you’re having connection issues, double-check your proxy credentials and make sure you’re using the correct endpoint and port for your chosen product.
- The proxy password format (
your_password_session-anychars_mode-speed
) includes additional parameters. Make sure to replaceyour_password
with your actual password while keeping thesession-anychars_mode-speed
part intact. - For HTTPS connections, you might need to handle SSL certificate errors. You can add the following option to ignore SSL errors (use with caution in production):
chrome_options.add_argument('--ignore-certificate-errors')
- Remember to handle errors appropriately in your production code, as network requests can fail for various reasons.
By following this guide, you should now be able to successfully integrate Evomi’s proxies with your Selenium scripts for web automation and scraping tasks.