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.
pip install selenium-stealthVerified import paths — ran on the pinned version, not inferred.
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=...)`.
Consider `pip install stealthenium` and updating your imports and usage according to its documentation.
Ensure you are using `selenium.webdriver.Chrome` with compatible Chrome browser and ChromeDriver versions.
For highly resistant websites, consider running in headful mode (without `--headless`), adding realistic delays (`time.sleep()`), simulating mouse movements, and using rotating proxies.
Rely on `selenium-stealth`'s default parameter values, or be extremely careful when customizing parameters like `languages`, `vendor`, `platform`, `webgl_vendor`, and `renderer` to ensure they form a consistent, realistic browser fingerprint.
Update your ChromeDriver to match your Chrome browser version. Check `chrome://settings/help` for your Chrome version, then download the corresponding ChromeDriver from the official site. Also, ensure sufficient system resources and add `--no-sandbox` if running in a containerized environment.
Beyond `selenium-stealth`, consider: 1) Using `undetected_chromedriver` (a separate project designed for this purpose). 2) Adding random delays (`time.sleep()`) and simulating human-like interactions (scrolls, mouse movements). 3) Rotating IP addresses with proxies. 4) Avoiding headless mode or configuring it very carefully. 5) Maintaining browser profiles (cookies) to build 'trust'.
Implement `time.sleep()` for random delays between actions. Use Selenium's explicit waits (`WebDriverWait` and `expected_conditions`) to ensure elements are present, visible, and clickable before interacting with them. Mimic human scrolling behavior.