Prompt
How do I automate scraping across hundreds of sites without constant maintenance?
Latest observation
To automate scraping across hundreds of sites with minimal maintenance, the key is to reduce site-specific logic and build a resilient, configurable scraping system instead of one-off scrapers.
1) Prefer a multi-layer approach
Use the simplest method that works for each site:
- API first: Check for public APIs, RSS feeds, JSON endpoints, sitemap.xml, or embedded structured data.
- HTML parsing: Use selectors for stable content.
- Headless browser only when necessary: Reserve Playwright/Selenium for sites that rely heavily on JavaScript.
This avoids overengineering and cuts breakage.
2) Build a configurable scraper framework
Instead of hardcoding per site, store each site’s rules in config:
- start URL(s)
- pagination pattern
- selectors for title, price, date, etc.
- rate limits / concurrency
- login/session requirements
- extraction fallback rules
Example idea:
site_config.yaml or a database table per source.
That way, when a site changes, you update config rather than rewriting code.
3) Normalize extraction with a common schema
Map all scraped data into a standard model, like:
- source
- URL
- canonical ID
- title
- body/snippet
- author
- published_at
- price
- category
- scraped_at
This makes downstream processing consistent even if source pages vary.
4) Use robust selectors and fallback strategies
Avoid brittle absolute XPaths or long CSS chains. Prefer:
- semantic selectors (
article,h1,time,meta[property=...]) - multiple fallback selectors per field
- text-based validation
- regex cleanup for extracted values
For example:
- try schema.org JSON-LD
- then OpenGraph/meta tags
- then page text selectors
5) Detect and handle change automatically
Most maintenance comes from site layout changes. Reduce impact by adding:
- selector health checks: alert when extraction yields null or empty values
- sample validation: compare counts/field lengths to historical norms
- diffing: compare current DOM structure to previous snapshots
- automatic retries with alternate extraction paths
When one method fails, the system should degrade gracefully instead of breaking.
6) Make crawling polite and adaptive
To avoid blocks and reduce breakage:
- obey robots.txt where required
- throttle requests per domain
- randomize intervals slightly
- rotate user agents carefully
- use session persistence where needed
- back off on 429/403/5xx responses
- cache pages and avoid re-fetching unchanged content
7) Separate fetching, parsing, and storage
Use a pipeline architecture:
- Fetcher: downloads pages
- Parser: extracts structured data
- Normalizer: cleans and standardizes fields
- Storage: writes to DB/object store
- Monitor: tracks failures and quality
This makes debugging much easier.
8) Add observability
If you want low maintenance, you need visibility:
- error logs by domain
- success/failure rates
- missing field counts
- extraction confidence
- page response codes
- time-to-scrape per site
Set alerts when:
- a site’s success rate drops
- extracted item counts collapse
- fields start coming back empty
9) Use change-tolerant extraction techniques
Good practices:
- parse JSON-LD and metadata first
- use XPath/CSS with multiple variants
- scrape from structured tables when possible
- tolerate optional fields
- don’t assume page order
- store raw HTML snapshots for failed cases
10) Consider LLM-assisted extraction only as a fallback
For highly variable pages, LLMs can help transform messy HTML into structured data, but don’t rely on them as the primary extractor for everything. They’re better as a fallback for:
- layout changes
- uncommon sites
- low-volume edge cases
If you use them:
- constrain output with a schema
- validate results strictly
- keep deterministic parsers as the first line
11) Schedule recrawls intelligently
Don’t scrape everything constantly.
- crawl high-change sites more often
- use ETags/Last-Modified headers when possible
- detect updates via feeds/sitemaps
- prioritize pages likely to change
- reprocess only changed records
12) Keep site onboarding cheap
For hundreds of sites, you need a repeatable onboarding workflow:
- identify source type
- test for API/JSON-LD/meta tags
- define config
- run sample crawl
- validate output
- add monitoring thresholds
A template-based onboarding process saves a lot of time.
A practical stack
A common production setup is:
- Python
- Scrapy for crawling
- Playwright for JS-heavy sites
- BeautifulSoup/lxml for parsing
- Redis/Celery or Kafka for queues
- PostgreSQL + object storage for data
- Prometheus/Grafana + alerting for monitoring
The core principle
If you want to avoid constant maintenance, don’t build “100 custom scrapers.”
Build one resilient scraping platform with:
- configurable rules
- multiple extraction fallbacks
- monitoring
- automatic retries/backoff
- normalization
If you want, I can also give you:
- a reference architecture for this system, or
- a Python/Scrapy + Playwright template for hundreds of sites.