Skip to main content
Selenium

Setting Up Selenium with Python Using NodeMaven Proxies and IP Whitelisting

Cornel avatar
Written by Cornel
Updated over a month ago

Selenium is a powerful open-source tool for automating web browsers. It supports multiple programming languages, including Python, Java, and C#. Selenium is widely used for web testing, scraping, and automating repetitive tasks. It works across browsers like Chrome, Firefox, and Edge, and offers robust features for interacting with web elements.

For more information on Selenium please visit their website:

Setup

Before anything, check if Python is installed: Open a terminal (Command Prompt or shell) and type the following command:

python --version

If Python is installed, this will display the version number:

In this case please go to Step

Step 1: Install Python

  1. Download Python from the official website: https://www.python.org/downloads/.

2. Run the installer and make sure to check the option “Add Python to PATH” during installation.

Step 2: Install Selenium and WebDriver

  1. Run this command to install Selenium:

pip install selenium

2. Run this command to install WebDriver:

pip install webdriver-manager

Step 3: Create a project directory

mkdir selenium_project

  • Navigate to the newly created directory and create a subdirectory for scripts:

cd selenium_project
mkdir src

Step 4: Write Your Selenium Script

  1. Open a text editor and paste the following script:

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# Configure proxy with IP whitelisting
proxy = "http://gate.nodemaven.com:8080" # Replace with your proxy string

# Set Chrome options to use the proxy
chrome_options = Options()
chrome_options.add_argument(f"--proxy-server={proxy}")

# Initialize WebDriver
driver = webdriver.Chrome(
service=Service(ChromeDriverManager().install()),
options=chrome_options
)

try:
# Navigate to an IP-checking service
driver.get("https://www.maxmind.com/en/locate-my-ip-address")
print("Page title:", driver.title)

# Extract the IP address from the page (if displayed)
page_source = driver.page_source
print("Page content loaded. Check the browser to verify the proxy works.")
except Exception as e:
print("An error occurred:", e)
finally:
# Close the browser
driver.quit()

2. Save the file as selenium_test.py inside the src directory.

Step 5: Run Your Script

  1. Open Command Prompt and navigate to the src directory and then run the following command:

python selenium_test.py

Expected output:

  1. The browser will open, navigate to https://www.maxmind.com/en/locate-my-ip-address, and display your IP address and related details.

2. The Command Prompt will print the page title:

Now you are ready to personalize your script and start using Selenium with NodeMaven proxies!

Did this answer your question?