跪拜 Guibai
← All articles
GitHub · Web Crawling · AI Programming

Scrapling Unifies HTTP, Browser, and Anti-Detection Crawling Under One Session Layer

By 王若风 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Scrapling introduces a Session Dispatcher Pattern that decouples how data is fetched from how it is processed, letting a crawler switch from a fast HTTP call to a stealth browser at runtime without rewriting logic. The trade-off is a bus factor of one and deep coupling to a proxy-service ecosystem that funds the project.

Summary

A typical web scraper today drags in a tangle of dependencies: requests for HTTP, Playwright for JavaScript, Scrapy for scheduling, and custom scripts to dodge Cloudflare. Scrapling collapses that stack into one library by introducing a unified session layer. Three fetcher types—HTTP, dynamic browser, and stealth browser—share the same interface and return the same Response object, so a spider can route a request to the right channel with a single session ID parameter.

Under the hood, adaptive element tracking uses SQLite-stored fingerprints and difflib similarity matching, not machine learning. The Spider engine runs on anyio for async portability, checkpoints crawler state atomically to prevent corruption, and respects robots.txt Crawl-delay directives by taking the stricter of the user setting and the site requirement.

Benchmarks that claim a 700x speedup over BeautifulSoup are misleading; the real gap against Parsel is under 1%. The project is a solo effort with 1,450 commits from one developer, and its anti-detection strength depends heavily on paid proxy services, which also sponsor the project.

Takeaways
Three fetcher types—FetcherSession (HTTP via curl_cffi), DynamicSession (Playwright), and StealthySession (Patchright)—share one interface and one Response object.
A spider routes requests to a fetcher by session ID at runtime; lazy=True defers browser launch until a stealth request actually arrives.
Adaptive element tracking stores fingerprints (tag, class, text, attributes) in a WAL-mode SQLite database and matches with difflib.SequenceMatcher, not ML.
The CSS-to-XPath translator is adapted from Parsel; the original work is in storage and element relocation.
CrawlerEngine uses anyio instead of raw asyncio, keeping the door open for trio compatibility.
CheckpointManager writes state to a .tmp file and atomically replaces the official file to avoid corruption on interruption.
robots.txt handling takes max(user delay, site Crawl-delay), so site rules are never overridden by user config.
Benchmarks showing a 700x lead over BeautifulSoup compare against deliberately slow parsers; the gap against Parsel is under 1%.
The project has 1,450 commits from one developer (D4Vinci); the next contributor has 10.
All 11 Platinum Sponsors are proxy services, embedding the framework directly into the paid-proxy supply chain.
MCP server integration (for AI agents like Claude) still crashes on pages containing U+0008 control characters as of v0.4.10.
The new Scrapy integration decorator (@scrapling_response) is four days old and has almost no community feedback.
Conclusions

Scrapling’s real innovation is not any single fetcher but the Session Dispatcher Pattern: a runtime-routed abstraction that treats HTTP, browser, and stealth channels as interchangeable backends.

The adaptive element matching is deliberately low-tech—SQLite plus difflib—and that restraint makes it more trustworthy than a black-box ML approach would be.

Publishing benchmarks against BeautifulSoup when your parser is a Parsel derivative inflates the performance story; the honest comparison would be against Parsel, where the difference is negligible.

A solo-maintainer project with proxy-service sponsors faces a structural tension: the framework’s anti-detection value is tied to paid infrastructure the author has a commercial incentive to promote.

The anyio choice is a quiet signal of future-proofing; it costs little now but lets the engine run on trio if asyncio becomes a bottleneck or if the ecosystem shifts.

Concepts & terms
Session Dispatcher Pattern
A design where multiple data-fetching backends (HTTP, browser, stealth browser) implement the same interface and return the same response type, with channel selection made at runtime via a session ID rather than hardcoded in application logic.
WAL mode (Write-Ahead Logging)
A SQLite journal mode that allows concurrent reads and writes by logging changes to a separate file before applying them to the main database, avoiding table locks during multi-threaded access.
anyio
A Python async networking library that provides a single API compatible with both asyncio and trio event loops, letting framework authors support multiple async backends without writing separate code paths.
Patchright
A fork of Playwright modified specifically for browser automation that evades detection, used by Scrapling’s StealthySession to launch Chromium instances that websites cannot easily identify as bots.
MCP (Model Context Protocol)
A protocol that lets AI agents such as Claude or Cursor call external tools through a standardized server interface; Scrapling wraps its crawling capabilities as an MCP server so agents can fetch web pages directly.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗