How souzadevinicius/scrapling works
Project Type and Purpose
• Scrapling as an open-source Python web scraping library.
• Its purpose is to allow users to fetch web pages stealthily (bypassing anti-bot measures), parse HTML documents with resilience against structure changes, and offer advanced selection techniques (e.g., auto-matching, CSS/XPath, text/regex filtering).
High-Level Components
A. User Interface / Entry Points
– Command-line interface (CLI module) and Python API.
– Represented by “scrapling/cli.py” and the “defaults” module used to import Fetcher classes.
B. Fetching Layer
– Main Fetcher classes: Fetcher, AsyncFetcher, StealthyFetcher, and PlayWrightFetcher.
– Show these as separate but related components that abstract HTTP requests.
– Each Fetcher wraps third-party libraries (for example, httpx, Camoufox, or Playwright) and configures options for stealth mode, retries, etc.
C. Engine Layer
– “scrapling/engines” contains various engines (camo, pw, static) and the “toolbelt” submodule with bypass scripts.
– Represent these as components that act as plugins or adapters for different request strategies.
D. Core Parsing and Processing Layer
– “scrapling/core” holds the central parsing logic: custom types, mixins, storage adaptors, translator, and utility functions.
– Illustrate that once a page is fetched, the raw content is passed into the core for parsing and element abstraction (creating the “Adaptor” objects).
– Indicate subcomponents handling element navigation (parent, children, siblings traversal), auto-matching (saving and later relocating element properties), and content-based search methods (regex, CSS, XPath).
E. Storage and Auto-matching Subsystem
– While not a separate directory itself, the README makes clear that the library automatically saves unique properties of HTML elements to enable later auto-matching.
– Show the data flow: when an element is first selected with auto_save enabled, its unique properties are stored; later, when auto_match is requested, the stored data is used to relocate the element.
F. Testing and Documentation
– These indicate quality control and developer guidance.
G. Integration Points/External Services
– Represent integration with third-party libraries (httpx, Camoufox, Playwright, possibly orjson for JSON operations) and even external services or browsers if real_chrome is used.
– Optionally include sponsorships as a note on how further integrations (for proxies, for example) might appear.
Relationships and Interactions
– Include lines indicating dependencies on external libraries or services (e.g., httpx, Camoufox, Playwright) adjacent to the appropriate fetchers.
Architectural Patterns and Design Principles
– Emphasize the Adapter/Facade pattern: the fetchers hide the complexities of underlying request engines and adapt the responses to a standardized “Adaptor” object.
– Highlight modularity and separation of concerns: distinct directories for core functionality, engine-specific operations, CLI, and tests.
– Note the extensibility: the “toolbelt” and engine submodules are designed to be easily extended for additional bypass techniques.
Additional Elements
• The entry point (CLI/API usage) → fetching layer (with various Fetcher classes routing through engines) → core parsing and processing (generating Adaptor objects, applying selectors and auto-matching) → storage (maintaining element properties) and testing/documentation support.