Selenium Stealth

1.0.6 · maintenance · verified Thu Apr 16

Selenium Stealth is a Python library designed to make Selenium WebDriver more stealthy, aiming to bypass anti-bot detection systems on websites. It achieves this by modifying various browser properties and behaviors that typically reveal automated browsing, such as the `navigator.webdriver` flag, user-agent, and WebGL fingerprints. The library currently supports Chrome/Chromium and is at version 1.0.6. While still functional for many use cases, its last update on PyPI was in November 2020, and there is an actively maintained fork, `stealthenium`, for those seeking ongoing development.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes a Chrome WebDriver instance with common options to hide automation indicators, then applies the `selenium-stealth` modifications. It navigates to a known bot detection test site (`sannysoft.com`) to demonstrate its effect. Ensure you have `chromedriver` compatible with your Chrome browser version, either in your system PATH or specified via `Service(executable_path=...)`.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium_stealth import stealth
import time

# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("start-maximized")
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option('useAutomationExtension', False)

# Configure ChromeDriver service (optional for Selenium 4.6+ if Chrome is in PATH)
# If ChromeDriver is not in PATH, uncomment and set executable_path
# service = Service(executable_path='/path/to/chromedriver')
# driver = webdriver.Chrome(service=service, options=chrome_options)

# For Selenium 4.6+ and Chrome in PATH, direct initialization is often sufficient
driver = webdriver.Chrome(options=chrome_options)

# Apply stealth settings
stealth(
    driver,
    languages=["en-US", "en"],
    vendor="Google Inc.",
    platform="Win32",
    webgl_vendor="Intel Inc.",
    renderer="Intel Iris OpenGL Engine",
    fix_hairline=True,
)

print("Navigating to a test site...")
driver.get("https://bot.sannysoft.com/") # A common site to test bot detection
time.sleep(5) # Give some time for the page to load and scripts to run
print(f"Page title: {driver.title}")

# Add your scraping logic here

driver.quit()
print("Browser closed.")

view raw JSON →