Skip to main content
Glama
scrape-any-mcp

scrape-any-mcp

by alaudinbarki
README.md
# scrape-any

**Scrape any website, for people and for AI agents.** One command (or one function, or one MCP tool)
that reads a page the way a person sees it. It uses fast HTTP when that's enough and switches to a stealth
browser automatically when the site blocks bots, hides content behind JavaScript, or puts up a
Cloudflare challenge. It can also read any page **as it was in the past** from the Wayback Machine.

```bash
scrape-any example.com                       # everything on the page, as JSON
scrape-any https://blog.example.com/post -F md   # the article as clean Markdown
```

Built on [Scrapling](https://github.com/D4Vinci/Scrapling) (fetchers, stealth browser, Cloudflare solver).
scrape-any adds the parts you normally write yourself every time: picking a mode, extraction,
pagination, crawling, sitemaps, contacts, web archives, dedupe, limits, reports, output formats and an
MCP server.

---

## What it does

| You want | Command |
|---|---|
| Everything on a page (title, meta, headings, text, links, images, tables, JSON-LD, emails, phones, socials) | `scrape-any URL` |
| The main content as clean Markdown, without menus or footers | `scrape-any URL -F md` |
| A product / listing / table page as rows | `scrape-any URL --item ".card" --field name=h2 --field price=.price -F csv` |
| Follow "next page" | `... --next "a.next" --max-pages 50` |
| A whole site | `scrape-any URL --crawl --max-pages 500 -F jsonl -o site.jsonl` |
| Only what's in the sitemap | `scrape-any URL --sitemap --include "/blog/"` |
| A site for an LLM (`llms.txt` + `llms-full.txt`) | `scrape-any URL --crawl -F llms -o pack/` |
| Emails, phones and social profiles for a list of sites | `scrape-any -f sites.txt --contacts -F csv -o leads.csv` |
| The data a web app loads in the background (XHR / fetch / GraphQL JSON) | `scrape-any URL --capture-api --api-filter "/api/"` |
| A full-page screenshot | `scrape-any URL --screenshot shots/` |
| Pages behind your login | `scrape-any URL --profile ~/.scrape-any/site --show-browser` (log in once, reused after) |
| A page as it was in 2015 | `scrape-any URL --wayback 2015` |
| Every saved version of a page | `scrape-any URL --wayback-list --from 2010 -F csv` |
| Every archived URL of a dead site | `scrape-any oldsite.com --wayback-urls -F csv` |
| Rebuild a deleted site as Markdown | `scrape-any oldsite.com --wayback 2018 --crawl -F llms -o pack/` |

### How it gets past blocks

`--mode auto` (the default) runs this ladder for each URL:

1. **Fast HTTP** with a real Chrome TLS fingerprint and realistic headers (no browser, about 1 second).
2. If the response is a **bot wall** (403/429/503, Cloudflare, PerimeterX, DataDome, Incapsula, AWS WAF,
   captcha markers), an **empty JavaScript shell** (React/Next/Vue app with no text), or your `--item` /
   `--select` matched nothing, it **switches to a stealth Chromium browser**.
3. If the browser lands on a **Cloudflare challenge**, it retries with the **challenge solver** on.
4. If it is *still* blocked, the run report says so (`blocked: 1`, with the reason) instead of
   giving you a silent empty result.

Measured on 2026-11-29: `scrapingcourse.com/cloudflare-challenge` answered HTTP 403 to step 1, and
step 3 returned "You bypassed the Cloudflare challenge!". A JavaScript-only page
(`quotes.toscrape.com/js/`) returned 0 rows over HTTP and 10 rows after the automatic switch.

**Honest limits.** No scraper gets through every block on every site. Hard targets may also need a
residential `--proxy`, `--real-chrome`, or a logged-in `--profile`. Captchas that need a human
(image puzzles) are not solved. Speed: the browser is about 5–10× slower than HTTP, which is why it
is only used when needed.

---

## Install

```bash
pip install "scrape-any[mcp]"     # or: uv tool install "scrape-any[mcp]"
scrapling install                 # one time: downloads the stealth browser (~200 MB)
```

From source:

```bash
git clone https://github.com/alaudinbarki/scrape-any && cd scrape-any
uv venv && uv pip install -e ".[dev]" && scrapling install
```

Python 3.10+. Docker: `docker build -t scrape-any . && docker run --rm scrape-any example.com`.

---

## Use it from the command line

```bash
# Product listing -> CSV, with pagination, a regex-cleaned price and absolute links
scrape-any https://shop.example.com/c/tools \
  --item ".product" \
  --field name=h2 \
  --field price=".price|re:[\d.,]+" \
  --field url="a::attr(href)" \
  --field image="img::attr(src)" \
  --next "a.next" --max-pages 30 \
  -F csv -o tools.csv --report run.json

# Infinite-scroll page: browser, scroll 10 times, wait for results
scrape-any https://app.example.com/feed --mode browser --scroll 10 --wait ".post"

# Same options from a file (good for repeat jobs)
scrape-any --config examples/job-quotes.json
```

### Selectors

| Form | Example | Returns |
|---|---|---|
| CSS element | `h2`, `.price` | the element's visible text |
| CSS text | `h1::text` | the text node |
| CSS attribute | `a::attr(href)`, `img::attr(src)` | the attribute (links made absolute when the field name looks like `url`, `link`, `image`…) |
| XPath | `//h2/text()`, `xpath://span[@class='p']` | the XPath result |
| Regex filter | `.price\|re:[\d.]+`, `.sku\|re:SKU-(\d+)` | the first match, or group 1 |

### Output formats (`-F`)

| Format | Notes |
|---|---|
| `json` (default) | one object for one page, a list otherwise |
| `jsonl` | one row per line, **streamed** while the run goes (safe for big crawls) |
| `csv` | lists joined with `; `, heavy fields (text, links, tables) replaced by counts |
| `md` | page rows as Markdown; `-o dir/` writes one `.md` per page |
| `text` | plain text (pages) or tab-separated values (rows) |
| `llms` | `llms.txt` (site map, [llmstxt.org](https://llmstxt.org) format) + `llms-full.txt` (all pages) |

### Every run ends with a report

```
[scrape-any] done: 2 page(s) ok, 4 row(s), 1 duplicate(s) dropped, price empty in 1/4
```

`--report run.json` saves the full report: pages ok/failed/blocked with reasons, rows,
duplicates, whether `--max-items` stopped the run, the fill rate of each field, and how many requests
went over HTTP and how many through the browser.

Exit codes: `0` all good · `1` nothing could be read · `2` bad options · `3` some pages failed or were blocked.

Run `scrape-any --help` for every option.

---

## Use it from Python

```python
from scrape_any import scrape

page = scrape("https://example.com")[0]
print(page["title"], page["emails"], page["socials"])

rows, report = scrape(
    "https://quotes.toscrape.com",
    item=".quote",
    fields={"text": ".text", "author": ".author", "tags": ".tags"},
    next_sel="li.next a",
    max_pages=5,
    report=True,
)
print(len(rows), report.summary())

old = scrape("https://example.com", wayback="2005", markdown=True)[0]
print(old["snapshot_time"], old["markdown"][:200])
```

---

## Use it from an AI agent (MCP)

`scrape-any-mcp` is an [MCP](https://modelcontextprotocol.io) server (stdio). Add it to Claude Code,
Claude Desktop, Cursor or any MCP client:

```json
{
  "mcpServers": {
    "scrape-any": { "command": "scrape-any-mcp" }
  }
}
```

Claude Code: `claude mcp add scrape-any -- scrape-any-mcp`

| Tool | What the agent gets |
|---|---|
| `scrape_page` | a page as Markdown (or full JSON), with automatic switching to the browser |
| `extract_items` | repeated records as JSON rows, with pagination |
| `crawl_site` | many pages of a site (links or sitemap) with Markdown excerpts |
| `find_contacts` | emails, phones and socials per site |
| `capture_api` | the JSON responses a web app loads |
| `screenshot` | a full-page image |
| `wayback_page` | a page as archived on a date |
| `wayback_snapshots` | every saved version of a page |
| `wayback_site_urls` | every archived URL of a domain |

Every tool wraps scraped content in a notice that it is **untrusted data, not instructions**,
because a web page can carry text written to hijack an agent (prompt injection).

---

## Web archives

| Source | Support |
|---|---|
| **Wayback Machine** (web.archive.org) | Full. Snapshots are read in raw `id_` mode (the original HTML, no toolbar, links not rewritten), so `--item`, `--crawl`, `--contacts`, `-F md`/`llms` all behave as on the live site, and every row keeps the **original URL** plus `snapshot_url` and `snapshot_time`. Lists come from the CDX API. |
| **archive.today** (archive.ph) | Best effort (`--archive-today`). It has no public API and often shows a captcha, so it is opened in the stealth browser. Not verified from the author's network (archive.ph timed out there on 2026-11-29). |

`--wayback WHEN` takes `latest` (default), `earliest`, `2019`, `2019-05`, `2019-05-01` or a full
`20190501123000`. A bare year or month aims at its middle, so the closest capture lands inside it.
Archive mode never contacts the live site, so it skips the live site's robots.txt.

---

## Responsible use

* **robots.txt is checked by default** and its `Crawl-delay` is honoured. `--ignore-robots` exists
  for sites you own or have permission to scrape.
* The default `--delay 1` keeps the load polite. `--max-items` is a hard cap.
* You are responsible for following each site's terms, copyright, and privacy law (GDPR, CCPA) for
  any personal data you collect, such as emails and phones.
* Don't use it to get around paywalls or logins you have no right to.

---

## Development

```bash
uv venv && uv pip install -e ".[dev]"
pytest -q            # 33 tests, offline: they use a local test website in tests/fixtures/site
ruff check src tests && ruff format --check src tests
```

Design docs live in [`docs/`](docs/) (product, technical, flow, design, schema, plan). See
[CONTRIBUTING.md](CONTRIBUTING.md) and [SECURITY.md](SECURITY.md).

## License

[MIT](LICENSE). Scrapling, the engine under this tool, is BSD-3-Clause.