scrapai-cli
Describe what you want to scrape in plain English. An AI agent builds the scraper, and Scrapy runs it.
A self-hosted command-line tool for collecting structured data from hundreds of websites without writing a scraper for each one. AI is used once per website, at build time. After that, crawls are deterministic, fast and free to rerun.
- articles from 81 news sites in 3 days
- 10.5Marticles from 81 news sites in 3 days
- to build scrapers for 50 sites
- <1 hrto build scrapers for 50 sites
- websites scraped in production
- 500+websites scraped in production
- AI cost per page once a scraper is built
- €0AI cost per page once a scraper is built
Why we built it
Our research needs data from hundreds of websites, scraped regularly and structured consistently. Great crawling frameworks exist, but at scale you still write code for every site, watch for breakage and fix things when layouts change. Ten scrapers is fine. A hundred is a full-time job. Five hundred is a team.
We looked at three options:
- Scraping services charge per page or per request. Fine at small volumes; at scale the bills get serious, and you lose access when you stop paying.
- Calling an LLM on every page is clever, but the cost grows with every page crawled, for what is ultimately a pattern-matching problem.
- AI once, deterministic forever. Use AI at build time to analyse the site and write extraction rules, then run those rules with Scrapy. The cost is per website, not per page. This is scrapai.
Read the full story: Why We Built Another Web Scraper (Sorry) →
How it works
Instead of a Python spider per website, an AI agent writes a JSON config that is validated and stored in a database. A single generic spider loads any config at runtime, so adding a website means adding a row.
You (plain English) → AI agent → JSON config → Database → Scrapy crawl
(once) (forever)You: "Add https://bbc.co.uk to my news project" Agent: [analyses the site, writes extraction rules, test-crawls, saves the config] You: "Here's a CSV with 200 websites, add them all" Agent: [queues them and works through them in parallel batches]
The agent documents what it found and why in plain language, so you can review its assumptions at any point, or write and edit configs by hand.
Safe by design: the agent writes config, not code
An agent that writes and runs Python has the power of an unsupervised developer, and every page it crawls is untrusted input that could contain prompt injections. scrapai limits the agent to producing data.
- Configs are validated with strict schemas before they reach the database or the crawler.
- URLs are checked: HTTP and HTTPS only, with private and local network addresses blocked.
- Settings are bounded (concurrency, delays) and extractor names are whitelisted.
- With Claude Code, permission rules stop the agent from editing framework code or running destructive commands.
- At crawl time there is no AI in the loop: Scrapy executes the config deterministically.
Features
- Clean, structured extraction. Articles come out as title, content, author and date; products, jobs and listings get custom field-level extraction.
- Cloudflare handling with cookie caching. A stealth browser solves the challenge once, then fast HTTP requests reuse the session: about 8 minutes for a 1,000-page crawl instead of 2+ hours.
- Smart proxy escalation. Starts direct, falls back to a proxy only when a site blocks, and remembers it.
- Pause and resume. Stop a long crawl and pick it up later with no progress lost.
- Incremental crawling. Skips already-scraped pages, cutting bandwidth by 80–90% on routine re-crawls.
- Database-first fleet management. Change a setting across every scraper with one query; export and share configs as JSON.
- Queues and batch processing. Bulk-add hundreds of sites with priorities, status tracking and retries.
- AI-assisted health checks. Detect broken scrapers and let the agent repair them after a site redesign, in 5–10 minutes instead of about 45 by hand.
- Flexible storage and export. SQLite or PostgreSQL, optional S3-compatible storage, and export to CSV, JSON, JSONL or Parquet.
In use
On a news research project, ten agents working in parallel built scrapers for 50 news sites in under an hour, about a minute per site. The crawlers then ran for three days and collected 10.5 million articles from 81 news sites across 16 countries. For each article the scrapers captured the title, body, date, authors, thumbnails, images and attached PDFs.
scrapai also collects the documents behind the Climate Insights Directory, a searchable index of 75,000+ climate reports from civil-society organisations worldwide, and runs in production across 500+ websites.
Get started
Requires Python 3.9+ and Git, on Linux or macOS. On Windows, use WSL or Docker for Cloudflare handling.
git clone https://github.com/discourselab/scrapai-cli.git cd scrapai-cli ./scrapai setup ./scrapai verify
Then open your coding agent in the folder and describe the site you want. Claude Code is what we use and test with; other agents that can run shell commands work too, and the setup step can use other models, including free self-hosted ones. Full guides are in the documentation.
Good fit, and not
- Good fit: teams scraping many websites, non-technical users who can describe what they need, and anyone building datasets from public web content such as news, research or documentation.
- Not yet: login-only or paywalled content, hard CAPTCHAs beyond Cloudflare challenges, form submission and click-based pagination.
Use it, or build with us
scrapai-cli is free and open source under Apache 2.0: no paid tier, no enterprise version, no metered API. Contributions are welcome, and we're happy to talk about large-scale data collection projects.