Skip to main content

scrapemend

Self-healing web scraping for Python. Describe the data you want once. scrapemend extracts it with cached CSS selectors — and when a site changes its markup and those selectors break, a language model inspects the new page, repairs the selectors, and caches the fix. The next run is free again.

Traditional scrapers break every time a site is redesigned. scrapemend treats a broken selector as a cache miss, not a crash.


Why

Every scraper hits the same wall: you write selectors, the site ships a redesign, your selectors silently return nothing, and you go rewrite them by hand. Cloud "AI scraping" services solve the robustness problem but are expensive, send your target data through someone else's servers, and run an LLM call on every request.

scrapemend takes the middle path:

  • Cache first. Known selectors run with zero LLM cost — it's just parsing.
  • Heal on miss. The LLM is only called when selectors stop matching.
  • Self-hosted. It's a library, not a service. Your keys, your data.

Install

pip install scrapemend

Quickstart

from scrapemend import Scraper, Schema

schema = (
    Schema("product")
    .add("title", "the product name")
    .add("price", "the product price with currency")
)

scraper = Scraper()  # offline stub by default; plug in a real LLM to heal
result = scraper.extract("https://shop.example/p/1", schema)

print(result["title"], result["price"])
print("healed:", result.healed, "tokens:", result.tokens)

You describe what you want in plain language. You never hand-write a CSS selector — scrapemend discovers them, and re-discovers them when they break.

How it works

extract(url, schema)
      │
      ├─ cached selectors exist? ──► apply them
      │                               ├─ all fields matched ──► return (free)
      │                               └─ some field missed ──┐
      │                                                      ▼
      └─ no cache ─────────────────────────────────► LLM heals selectors
                                                      apply, cache, return

Because healing only runs on a miss, steady-state scraping costs nothing in tokens. You pay the model exactly when a site actually changes.

Not just match/no-match

A redesign doesn't always break a selector cleanly. Sometimes the old selector still matches but now points at the wrong node — a struck-through "was" price, or the first card in a "related products" rail. Every field matches, the cache hits, and wrong data is returned for free: the same silent failure you were trying to avoid.

scrapemend guards against this by validating a cached extraction before trusting it:

schema = (
    Schema("product")
    .add("title", "the product name", expect="nonempty")
    .add("price", "the product price with currency", expect="number")
)

If a matched value fails its expect check (or a single-value field suddenly matches several nodes), that counts as a miss and triggers healing — instead of silently caching garbage. expect takes "number", "nonempty", or any str -> bool callable.

Status

Early alpha (0.0.2). The core pipeline — cache, parse, validate, heal, re-cache — works and is covered by tests that run fully offline. The LLM layer is provider-agnostic; OpenAI and DeepSeek adapters ship today.

Roadmap

  • Cache-first / heal-on-miss pipeline
  • Offline, key-free test path
  • OpenAI adapter
  • DeepSeek adapter
  • HTML condensing for cheaper prompts
  • Value validation (catch "matched but wrong node")
  • Selector fingerprinting (detect drift even when a value still passes)
  • Multiple selector sets per field (survive A/B and geo variants)
  • Local-model adapter
  • Pluggable cost/budget guards

License

MIT

Metadata

Release files for scrapemend 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapemend 0.0.2
File Size Uploaded Provenance
scrapemend-0.0.2.tar.gz 25.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for scrapemend 0.0.2
File Interpreter ABI Platform
scrapemend-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 42.2 kB

Release files / scrapemend-0.0.2.tar.gz

Download URL scrapemend-0.0.2.tar.gz
Size 25.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3c9a8f4e8efc723e205e86cb94c64c65149b9dec5904f0f3c243354b754ed884
BLAKE2b-256 checksum
How to use checksums
158fec248c5f6d05b1748b90463752e20a281dc2f83391a45bbd69e760e46db1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / scrapemend-0.0.2-py3-none-any.whl

Download URL scrapemend-0.0.2-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
874a322fd4d974d1caa032ad95443d318c3e0cd180d71f96170714e14ebf92be
BLAKE2b-256 checksum
How to use checksums
c40dbe077faa48d985f8bccc90705b3e96eeb165b31226c259be99c51984bbea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Security for scrapemend 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page