ProxyTee
TutorialUpdated 2026-08-288 min readBy Alex Mercer, Lead Network Architect

Web Scraping with Selenium and ProxyTee: A Comprehensive Guide

Master headless browser automation and dynamic JavaScript web scraping with Python Selenium WebDriver and ProxyTee rotating residential proxies.

Web Scraping with Selenium and ProxyTee: A Comprehensive Guide — ProxyTee Rotating Residential Proxies
Key Takeaways & Technical Summary

Master headless browser automation and dynamic JavaScript web scraping with Python Selenium WebDriver and ProxyTee rotating residential proxies.

In the realm of web scraping, understanding the nuances of various libraries and tools is crucial. Selenium, primarily known as a web automation tool, is often employed for web scraping, especially when dynamic content is involved. This guide explores how to leverage Selenium with ProxyTee to enhance your web scraping capabilities.

Web Scraping with Selenium and ProxyTee: A Comprehensive Guide — Architecture & Proxy Configuration Workflow

How Selenium Works for Web Scraping

Selenium simulates user behavior by interacting with a browser. It automates actions like clicking, scrolling, and form filling through scripts. While Selenium is not designed primarily for scraping, it can be used effectively with Python to control a browser, navigate the DOM (Document Object Model), and extract data using methods like find_element and find_elements.

Setting Up Selenium for Web Scraping with ProxyTee

To begin, ensure you have Python 3.x installed. Start by installing the Selenium WebDriver package using:

pip install selenium

You’ll also need a web browser like Chrome, and its corresponding driver. ProxyTee can assist with overcoming issues such as browser driver incompatibility by providing proxies to control the browser on the OS level, enhancing the automation process.

Basic Selenium Operations

First, initialize a browser instance. Here's how you can launch Chrome and open a webpage:

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://www.example.com") # Replace with your target URL
time.sleep(5) # Give page time to load
driver.quit()

You can run the browser in headless mode (without GUI) for server environments:

from selenium import webdriver
from selenium.webdriver import ChromeOptions

options = ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
driver.get("https://www.example.com")

print(driver.page_source)
driver.quit()

Locating and Extracting Elements with Selenium

Selenium provides methods to locate elements within web pages. Use find_element to extract specific data from HTML elements based on tags, classes, XPath, or CSS selectors:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions

options = ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
driver.get("https://sandbox.oxylabs.io/products") # Replace with your target URL

h1_tag = driver.find_element(By.TAG_NAME, "h1").text
h1_class = driver.find_element(By.CLASS_NAME, "css-1128ess").text
h1_xpath = driver.find_element(By.XPATH, "//h1").text
h1_css = driver.find_element(By.CSS_SELECTOR, "h1").text

print('\n'.join([h1_tag, h1_class, h1_xpath, h1_css]))
driver.quit()

Use find_elements to extract a list of elements, such as product titles from a webpage:

all_h4 = driver.find_elements(By.TAG_NAME, "h4")
for h4 in all_h4:
    print(h4.text)

XPath is necessary for accessing elements lacking a simple ID or class. It locates elements within the DOM, either absolutely from the root or using relative paths.

Handling Dynamic Content

For websites that use Javascript, waiting commands and other techniques such as scrolling are necessary.

Here's how to implement WebDriverWait() to wait for an element:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

options = ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
driver.get("https://sandbox.oxylabs.io/products")

try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.TAG_NAME, "h1"))
    )
    print(element.text)
finally:
    driver.quit()

Executing JavaScript with Selenium

Execute Javascript commands with execute_script. You can execute custom scripts to control actions on the page. Below is an example that executes JavaScript on the page using Selenium to interact with elements:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")

button = driver.find_element(By.CSS_SELECTOR, '[aria-label="Next page"]')
time.sleep(3)
driver.execute_script("arguments[0].click();", button)
time.sleep(5)
driver.quit()

Capturing Screenshots with Selenium

The following code allows capturing webpage screenshots:

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")
time.sleep(2)
driver.save_screenshot("screenshot.png")
driver.close()

Scaling Web Scraping with Proxies

For serious scraping projects, it is important to have scalability and avoid being blocked by the target server. This is where ProxyTee can significantly enhance your setup. Here’s why ProxyTee stands out:

  • Unlimited Bandwidth: With unlimited bandwidth, ProxyTee ensures your scraping projects don't halt due to data limits, vital for handling intensive data tasks.
  • Global IP Coverage: ProxyTee's global IP network, with millions of IP addresses across more than 100 countries, allows for robust, geo-diverse web scraping, making your scraping efforts more flexible and powerful.
  • Multiple Protocol Support: Supporting both HTTP and SOCKS5 protocols, ProxyTee provides essential versatility for handling various types of web data, enabling comprehensive scraping strategies.
  • Auto-Rotation: With automatic IP rotation from 3 to 60 minutes, ProxyTee helps to avoid IP blocks, an essential feature for reliable data gathering.
  • Affordability: ProxyTee offers a cost-effective solution for rotating residential proxies, allowing your team to stay within budget without compromising on performance. In comparison to Bright Data and other competitors, ProxyTee can be as low as 50% more affordable, a vital point for scaling scraping projects while managing costs effectively.

Using ProxyTee with Selenium

By integrating ProxyTee's residential proxies into your scraping scripts, you ensure IP rotation, which is vital in avoiding IP bans.

Scraping Multiple URLs and Storing Data

Use Selenium and ProxyTee to scrape multiple URLs. Here is an example:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()

urls = [f"https://sandbox.oxylabs.io/products?page={i}" for i in range(1, 11)]

for url in urls:
    driver.get(url)
    all_h4 = driver.find_elements(By.TAG_NAME, "h4")
    print(f"\nProduct titles for: {url}\n")
    for h4 in all_h4:
        print(f"{h4.text}")

driver.quit()

Save the scraped data in a CSV file for easier management using the pandas library. First install the libraries:

pip install pandas pyarrow

Now, modify the example to save scraped product data into a file.

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
import pandas as pd

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")
data = []

for i in range(1, 11):
    time.sleep(1)
    all_h4 = driver.find_elements(By.TAG_NAME, "h4")
    titles = "\n".join([h4.text for h4 in all_h4])
    data.append({"Page": i, "Titles": titles})

    button = driver.find_element(By.CSS_SELECTOR, '[aria-label="Next page"]').click()

df = pd.DataFrame(data)
df.to_csv('data.csv', index=False)
driver.quit()

Selenium versus other web scraping tools

While Selenium is an excellent tool for learning web scraping fundamentals, it does have its limitations. It is slower, uses more resources, and can easily be detected by anti-scraping systems, therefore limiting scalability. For larger-scale projects and targets, other tools could save time and resources.

Scrolling Pages with Selenium

Simulate scrolling actions through Javascript:

import time
from selenium import webdriver

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")
time.sleep(2)
driver.execute_script("window.scrollBy(0, 1000);") # scroll 1000px down
time.sleep(3)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight)") # scroll to bottom of page
time.sleep(3)
driver.quit()

Scroll by sending keys:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")
time.sleep(2)
driver.find_element(By.TAG_NAME, 'body').send_keys(Keys.END) # Scroll to bottom
time.sleep(3)
driver.quit()

Scroll to a specific element:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.get("https://sandbox.oxylabs.io/products")
time.sleep(2)

ActionChains(driver).scroll_to_element(driver.find_element(By.CLASS_NAME, "pagination")).perform()
time.sleep(3)
driver.quit()

Enhancing Selenium with ProxyTee's Rotating Residential Proxies

While Selenium is a powerful tool for scraping, it requires support for IP rotation to achieve scalability. ProxyTee's Unlimited Residential Proxies are specifically designed to solve this challenge, offering:

  • Unlimited bandwidth for data intensive operations.
  • Residential rotating proxies to avoid blocking or restrictions from target web servers.
  • Geo-targeting options for precise targeting, not just continent targeting.
  • Affordable pricing compared to competitors like Bright Data.

Integrating these proxies into your Selenium scraping process guarantees high performance, reliability, and scalability. Also, don’t forget the flexibility offered with other products from ProxyTee, like the Static Residential Proxies and the Datacenter Proxies.

Conclusion

Web scraping with Selenium is essential, especially if learning the basics is the primary goal, as it provides hands-on experience with browser automation and web interaction techniques. It also is a vital skill to understand, along with other fundamentals, like HTTP protocol. However, for scalability, it may require external support. With ProxyTee, you can utilize selenium with a powerful solution, allowing you to gather extensive web data without the usual restrictions. Whether you’re working on data aggregation or market research, combining Selenium and ProxyTee enhances the way you collect data.

Frequently Asked Questions about Selenium for Web Scraping

What is Selenium?

Selenium is a set of tools designed for web browser automation and testing. It consists of Selenium IDE, WebDriver, and Grid.

  • Selenium IDE is an interface to record and playback browser actions for automated testing.
  • Selenium WebDriver programmatically automates browser actions for more efficient and remote testing.
  • Selenium Grid enables parallel browser automation on different platforms.

What is Selenium used for?

Selenium is used for browser automation, web testing, and web scraping. In order to provide good UX/UI design, website and web applications must perform under various conditions. Selenium allows for testing under multiple load conditions, various browsers, OSes, and specific versions. Web scraping, is still possible though selenium may not be the best approach, when considering the features of specialized tools.

How to Use Proxies with Selenium?

Integrating proxies into Selenium requires setting proxy configurations in the WebDriver options to rotate IPs and avoid restrictions. Using ProxyTee's unlimited residential proxies offers a superior solution. With options for global coverage and automatic rotation, it is an excellent choice for managing high loads.

Selenium vs BeautifulSoup

Selenium is ideal for dynamic web pages rendered by Javascript and interactions like clicks. BeautifulSoup is suited to extract data from static HTML/XML and parse content with better efficiency, as there's no need to operate a browser. If dynamic content exists on the target site, Selenium will be necessary, while Beautiful Soup is better for simple parsing tasks. For large scale project with dynamic content, tools like ProxyTee make a huge difference.

Ready to Start Scraping with Enhanced Proxy Support?

Combining Selenium's automation capabilities with ProxyTee’s reliable proxy infrastructure empowers you to gather information seamlessly. ProxyTee is affordable, and integrates seamlessly with development workflows. Explore the advantages that ProxyTee brings to the table, and revolutionize the way you handle web data. You can get started here.

To scale this workflow in production without bandwidth throttling, explore our Enterprise Data Scraping Solutions, Selenium Proxy Integration, Germany Residential Proxies, and ProxyTee vs. Smartproxy (Decodo) Benchmark.

Technical FAQ

Frequently Asked Questions

When automating headless browsers with Selenium WebDriver, modern anti-bot firewalls (Cloudflare, Akamai, DataDome, PerimeterX) inspect ASN ownership, request velocity, and TLS fingerprints. Routing your traffic through ProxyTee's 30,000,000+ real household residential IPs across 100+ countries replaces flagged datacenter subnets with authentic consumer ISP connections.

Tags:SeleniumBrowser AutomationPython
AM
Alex Mercer • Lead Network & Web Scraping Architect
Technically Reviewed by Marcus Vance • Director of Proxy Infrastructure & Network Security

Principal infrastructure engineer at ProxyTee specializing in rotating residential proxy networks, SOCKS5/HTTP tunneling, TLS fingerprint mitigation, and distributed data extraction pipelines.