Metadata-Version: 2.4
Name: whispercrawler
Version: 0.1.0
Summary: An adaptive web scraping framework — fast, stealthy, and self-healing
Author: WhisperCrawler Contributors
License: BSD-3-Clause
Keywords: adaptive,async,crawling,scraping,stealth,web
Classifier: Framework :: AsyncIO
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Requires-Python: >=3.10
Requires-Dist: aiosqlite>=0.20.0
Requires-Dist: click>=8.1.0
Requires-Dist: cssselect>=1.2.0
Requires-Dist: ipython>=8.0.0
Requires-Dist: lxml>=5.2.0
Requires-Dist: markdownify>=0.13.0
Requires-Dist: msgspec>=0.18.0
Requires-Dist: orjson>=3.10.0
Requires-Dist: rich>=13.7.0
Provides-Extra: dev
Requires-Dist: mypy>=1.10.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.2.0; extra == 'dev'
Requires-Dist: ruff>=0.4.0; extra == 'dev'
Provides-Extra: fetchers
Requires-Dist: camoufox[geoip]>=0.4.0; extra == 'fetchers'
Requires-Dist: curl-cffi>=0.7.0; extra == 'fetchers'
Requires-Dist: patchright>=1.44.0; extra == 'fetchers'
Requires-Dist: playwright>=1.44.0; extra == 'fetchers'
Provides-Extra: mcp
Requires-Dist: mcp>=1.0.0; extra == 'mcp'
Description-Content-Type: text/markdown

# WhisperCrawler
*Adaptive web scraping — fast, stealthy, and self-healing.*

![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)
![License](https://img.shields.io/badge/License-BSD_3--Clause-blue.svg)
![Build](https://img.shields.io/badge/build-passing-brightgreen.svg)
![Coverage](https://img.shields.io/badge/coverage-80%25-brightgreen.svg)



## What it does
* **Bypasses advanced bot protection** using stealthy, heavily-patched headless browsers.
* **Rapidly extracts data** using a fast concurrent static HTTP fetcher (HTTP/3 + TLS fingerprinting).
* **Self-heals broken scrapers** by recovering elements based on layout and similarity heuristics when selectors fail.

## Quick start
```python
from whispercrawler import Crawler, GhostCrawler, ShadowCrawler, Spider, Response

# Static HTTP fetch (fastest)
page = Crawler.get("https://example.com")
print(page.css("h1::text").get())

# JavaScript-heavy site
page = GhostCrawler.fetch("https://spa-example.com", headless=True)
items = page.css(".product-card")

# Cloudflare-protected site
page = ShadowCrawler.fetch("https://protected.example.com")
price = page.css(".price::text").get()

# Adaptive parsing — survives site redesigns
page = Crawler.get("https://example.com")
title = page.css("h1", auto_save=True)           # saves fingerprint
# Later, after site redesign — finds element by similarity
title = page.css("h1", adaptive=True)

# Spider
class QuoteSpider(Spider):
    name = "quotes"
    start_urls = ["https://quotes.toscrape.com/"]
    concurrent_requests = 10

    async def parse(self, response: Response):
        for quote in response.css(".quote"):
            yield {
                "text":   quote.css(".text::text").get(),
                "author": quote.css(".author::text").get(),
            }
        next_page = response.css("li.next a::attr(href)").get()
        if next_page:
            yield Request(url=response.url + next_page)

QuoteSpider().start()
```

## Fetcher selection table
| Fetcher | When to use | Backend | Speed |
|---|---|---|---|
| Crawler | Static HTML, APIs, JSON endpoints | curl_cffi HTTP/3 | Fastest |
| GhostCrawler | JavaScript-rendered pages, SPAs | Playwright/Patchright Chromium | Medium |
| ShadowCrawler | Cloudflare, advanced bot detection | Camoufox (modified Firefox) | Slower |

## Adaptive parsing
WhisperCrawler introduces self-healing element selection. By adding `auto_save=True` to your CSS or XPath calls, it saves a detailed structural fingerprint of the matched element to a local SQLite database. If a site undergoes a redesign and your selector stops matching, switching to `adaptive=True` allows WhisperCrawler to search the DOM for elements that closely match the stored fingerprint (using tag, text similarity, attribute overlap, and DOM depth calculation), returning the closest match automatically.

## Installation
```bash
pip install whispercrawler
pip install "whispercrawler[fetchers]"   # for GhostCrawler and ShadowCrawler
pip install "whispercrawler[mcp]"        # for MCP server
whispercrawler install                   # download browser binaries
```

## CLI reference
| Command | Options | Description |
|---|---|---|
| `whispercrawler install` | `--force` | Download browser binaries required for Ghost/Shadow fetchers |
| `whispercrawler get <url>` | `--stealth`, `--ghost`, `--css <sel>`, `--xpath <sel>`, `--output <type>`, `--adaptive` | Fetch URL and extract elements via CLI |
| `whispercrawler shell` | | Launch interactive Python shell with preloaded environment |

## MCP server setup
WhisperCrawler includes a Model Context Protocol (MCP) server that exposes scraping tools to AI agents like Claude Desktop or OpenCode.

Configure your agent's MCP settings to add the `whispercrawler` server via stdio:
```json
{
  "mcpServers": {
    "whispercrawler": {
      "command": "whispercrawler-mcp",
      "args": []
    }
  }
}
```

## Session usage
Maintain shared persistent state (cookies, connection pools, proxies) across multiple requests using sessions.

```python
from whispercrawler import CrawlerSession, GhostSession, ShadowSession

# Static requests
with CrawlerSession(browser_type="chrome") as session:
    page1 = session.get("https://example.com/login")
    page2 = session.post("https://example.com/api", json={"user": "foo"})

# Playwright SPA session
with GhostSession(headless=True, max_pages=3) as session:
    page = session.fetch("https://example.com")

# Camoufox stealth session
with ShadowSession(humanize=True) as session:
    page = session.fetch("https://protected.com")
```

## ProxyWheel usage
Efficiently rotate through a pool of proxies using `ProxyWheel`. It automatically quarantines failed proxies for 5 minutes.

```python
from whispercrawler import Crawler, ProxyWheel

rotator = ProxyWheel(["http://proxy1:8080", "http://proxy2:8080"], strategy="least_used")

# Apply to a single request
page = Crawler.get("https://example.com", proxy_rotator=rotator)

# Or apply globally to the class
Crawler.proxy_rotator = rotator
```

## Interactive shell
The interactive shell provides a quick scratchpad to test scraping logic without writing full scripts. Running `whispercrawler shell` launches an IPython REPL with all fetcher classes, a persistent session history, and handy macros (like `curl2crawler()`) pre-imported to immediately begin querying pages interactively.

## License
**BSD 3-Clause License**

Copyright (c) 2025, WhisperCrawler Contributors

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


