pydoll Documentation

repository·main·Indexed 27 days ago

https://github.com/autoscrape-labs/pydoll

A stealth-first Python library for automating Chromium-based browsers (Chrome and Edge) without a WebDriver. Pydoll communicates directly with the Chrome DevTools Protocol (CDP) via WebSockets to simulate realistic human interactions, such as Bezier curve mouse movements and humanized typing, to bypass bot protections like Cloudflare Turnstile. It features structured data extraction with Pydantic, Shadow DOM support, HAR network recording, and hybrid UI/API automation.

Tokens
185.4K
Snippets
365
Records
703
Agent score
87%

What's inside pydoll

  1. Overview of element finding methods

    main

    Pydoll provides three distinct ways to locate elements depending on the information you have available:

    1. find(): Use when you know specific HTML attributes (e.g., id, class_name, name).
    2. query(): Use when you have a specific CSS selector or XPath expression.
    3. Traversal: Use when you want to explore the DOM starting from a known WebElement (e.g., using get_children_elements()).
  2. Overview of Browser Commands

    main

    The browser commands module provides low-level control over browser instances and their configuration. It is primarily used internally by Chrome and Edge classes, but can be used directly for advanced scenarios.

    Available capabilities include:

    • Retrieving browser version and user agent information.
    • Managing browser targets (tabs, windows).
    • Controlling global browser settings and permissions.
    • Handling browser lifecycle events.
  3. Overview of Pydoll

    main
    Pydoll is a web automation library designed to interact with browsers naturally. Unlike traditional automation tools, it connects directly to the Chrome DevTools Protocol (CDP), eliminating the need for external WebDriver configurations. It is designed for high-performance asynchronous tasks, web scraping, and testing, with a focus on mimicking human behavior to bypass anti-bot systems like reCAPTCHA v3 or Turnstile.
  4. Overview of Pydoll Command Modules

    main

    Pydoll provides high-level interfaces for interacting with Chrome DevTools Protocol (CDP) domains through specialized command modules. Each module corresponds to a specific CDP domain and provides methods for various browser operations:

    • Browser Commands (browser_commands.py): Browser-level operations and window management.
    • DOM Commands (dom_commands.py): DOM tree manipulation and element operations.
    • Input Commands (input_commands.py): Input event simulation (keyboard, mouse, touch).
    • Network Commands (network_commands.py): Network monitoring and request interception.
    • Page Commands (page_commands.py): Page lifecycle management and navigation.
    • Runtime Commands (runtime_commands.py): JavaScript execution and runtime management.
    • Storage Commands (storage_commands.py): Browser storage access (cookies, local storage, etc.).
    • Target Commands (target_commands.py): Target management and tab operations.
    • Fetch Commands (fetch_commands.py): Network request interception and modification.
  5. Overview of Browser Managers in Pydoll

    main
    The pydoll.browser.managers module provides specialized classes designed to handle specific aspects of the browser lifecycle and configuration. While these managers are primarily used internally by core browser classes like Chrome and Edge, they can be used directly for advanced automation scenarios or when extending the library.
  6. Understand Proxy Detection Techniques

    main

    Proxy detection is a probabilistic process where websites use multiple signals to determine if a connection is proxied. Understanding these signals helps in choosing the right proxy type and evasion strategy for Pydoll automation.

    Key Detection Vectors:

    • IP Reputation & ASN Classification: Websites check if an IP belongs to a datacenter (high risk, e.g., AWS, DigitalOcean) or a residential/mobile ISP (low risk). Residential and mobile proxies are harder to detect because they use legitimate ISP ASNs.
    • Geolocation Consistency: Mismatches between the IP's location and browser signals (Timezone via Intl.DateTimeFormat(), Accept-Language header, or physical impossibility of travel speed) trigger alarms.
    • HTTP Header Analysis: Presence of headers like Via, X-Forwarded-For, or X-Real-IP reveals proxies. Even the absence of standard headers or incorrect header ordering can be a signal.
    • Network Fingerprinting:
      • TCP/IP: Mismatches between the OS claimed in the User-Agent and the actual TCP stack characteristics (TTL, window size).
      • TLS (JA3/JA4): Fingerprints of the TLS ClientHello message. If the fingerprint doesn't match the browser claimed in the User-Agent, it is flagged.
      • HTTP/2: Specific settings frames and pseudo-header ordering unique to certain browsers.
    • Latency & Timing: Discrepancies between expected RTT (round-trip time) for a geographic location and the actual observed latency, or clock skew analysis.
    • Behavioral Analysis: Monitoring request timing, mouse movements, scrolling, and keyboard cadence to distinguish humans from bots.
  7. Understand Pydoll Tab instances

    main

    A Tab instance in Pydoll represents a single browser tab or window and serves as the primary interface for page automation. Each tab operates with its own independent context, including:

    • Execution Context: Isolated JavaScript runtime, DOM, and page state.
    • Event Handlers: Isolated callbacks for CDP events.
    • Network Monitoring: Separate tracking of HTTP requests, responses, and timing.
    • CDP Connection: A unique, direct WebSocket communication channel via a unique target_id.
  8. Core Concepts of Pydoll

    main

    Pydoll is built on several foundational architectural principles:

    • Zero-WebDriver Approach: Eliminates compatibility issues by avoiding the WebDriver protocol.
    • Async-First Design: Enables true concurrent operations for high-performance automation.
    • Native Chromium Support: Provides native support for multiple Chromium-based browsers.
  9. Pydoll Module Overview

    main

    Pydoll is organized into several functional modules:

    • Browser Module: Manages browser instances (Chrome, Edge), configuration (Options), and tabs (Tab).
    • Elements Module: Handles interaction with web page elements (WebElement).
    • Connection Module: Manages WebSocket communication via the Chrome DevTools Protocol.
    • Commands Module: Implements low-level CDP command implementations.
    • Protocol Module: Implements CDP domains (e.g., DOM, Network, Page, Runtime).
    • Core Module: Contains fundamental utilities, constants, and exceptions.
  10. Understand the Per-Tab WebSocket strategy

    main

    Pydoll utilizes a dual-connection model to balance browser-wide control with tab-specific automation:

    1. Browser-level Connection: A single connection to ws://localhost:port/devtools/browser/... used by the Browser instance for global operations like managing contexts, downloads, and browser-wide events.
    2. Tab-level Connections: Each Tab instance creates its own dedicated ConnectionHandler with a unique WebSocket connection to ws://localhost:port/devtools/page/{targetId}.

    Benefits of this approach:

    • True parallelism: Multiple tabs can execute CDP commands simultaneously.
    • Isolated failures: A connection issue in one tab does not impact others.
    • Independent event streams: Each tab receives only its own specific events without needing complex filtering.
  11. Key Advantages of Pydoll

    main

    Pydoll provides several core benefits for automation developers:

    • Zero WebDriver Dependency: No need to manage or configure external drivers (like ChromeDriver).
    • Human-like Interaction Engine: Capable of passing behavioral CAPTCHAs (e.g., reCAPTCHA v3, Turnstile) by mimicking real user patterns.
    • Asynchronous High Performance: Built for high-speed automation and parallel task processing.
    • Realistic Interaction Experience: Replicates real user behavior patterns.
    • Minimal Deployment: Designed to be 'install and use' out of the box.