Prompt
How do I crawl product pages across many ecommerce sites?
Latest observation
Crawling product pages across many ecommerce sites is doable, but the hard part is doing it safely, at scale, and in a way that survives different site structures. The best approach is usually a combination of:
- Prefer official data sources first
- Use a crawler only where needed
- Extract product data with site-specific rules
- Respect robots.txt, rate limits, and terms of service
Here’s a practical way to think about it.
1) Start with the easiest sources
Before crawling HTML pages, check whether the site exposes product data through:
- Sitemaps (
/sitemap.xml, product sitemaps) - Structured data on pages (
schema.org/ProductJSON-LD) - Feeds / APIs
- Pagination and category pages
- Internal search endpoints if allowed
Often, product pages already include structured data like:
<script type="application/ld+json">
{
"@type": "Product",
"name": "Running Shoe",
"sku": "123",
"offers": {
"@type": "Offer",
"price": "79.99",
"priceCurrency": "USD"
}
}
</script>
If that exists, extraction becomes much easier and more reliable.
2) Build a crawler pipeline
A robust pipeline usually has these stages:
A. Discovery
Find product URLs by crawling:
- category pages
- pagination
- sitemap URLs
- internal search results
B. URL normalization
Make sure you:
- remove tracking parameters
- canonicalize URLs
- deduplicate product URLs
Example of parameters to strip:
utm_*refsessionid- other tracking/query noise
C. Fetching
Use:
requests/httpxfor static pages- Playwright/Selenium for JS-heavy sites
D. Parsing
Extract:
- title
- price
- currency
- SKU / model
- availability
- images
- description
- brand
- category
- ratings/reviews if needed
E. Storage
Store raw HTML plus structured output:
- raw HTML for debugging
- parsed JSON for downstream use
3) Handle many ecommerce sites with a hybrid strategy
There are two main approaches:
Option 1: Generic extractor + fallback rules
Works well when many sites use similar patterns.
Try extracting from:
- JSON-LD
- microdata
- Open Graph tags
- meta tags
- common CSS selectors
This can cover a large percentage of sites with little per-site work.
Option 2: Site-specific templates
For sites that differ a lot, define a config per domain:
{
"example.com": {
"product_title": "h1.product-title",
"price": ".price .amount",
"availability": ".stock-status"
}
}
This is usually the most maintainable approach at scale.
4) Use structured data first
For product pages, the best source is often:
JSON-LDschema.org/ProductOffer,AggregateRating,Review
Why:
- less brittle than CSS selectors
- often cleaner and more complete
- less affected by layout changes
You can parse JSON-LD with a simple HTML parser and a JSON decoder.
5) Be careful with dynamic pages
Many ecommerce sites load product data via JavaScript.
Signs:
- page source has little content
- network requests load product info from an API
- price appears only after JS runs
In those cases:
- use Playwright to render the page, or
- inspect network calls and hit the underlying JSON endpoint directly if permitted
Direct API-style endpoints are often faster and more stable than browser rendering.
6) Respect crawl etiquette and legal constraints
Important:
- Check robots.txt
- Follow site terms of service
- Use reasonable request rates
- Add proper user-agent identification
- Implement retry/backoff
- Avoid overwhelming servers
If you’re crawling many sites, rate limit per domain:
- e.g. 1 request/second/domain, or slower
- queue by host to avoid bursts
7) Recommended tech stack
A common setup:
For crawling
- Scrapy for large-scale crawling
- Requests/httpx for simpler jobs
- Playwright for JS-heavy pages
For parsing
BeautifulSouporlxmlextructfor structured data extraction
For orchestration
- Celery / Kafka / Redis queue
- cron / Airflow / Prefect for scheduling
For storage
- PostgreSQL for structured product data
- S3 / blob storage for raw HTML
- Elasticsearch/OpenSearch if you need search
8) A simple architecture that works well
URL Frontier
- category pages, sitemap URLs, seeds
Crawler Workers
- fetch pages
- obey per-domain rate limits
Extractor
- parse JSON-LD
- fallback to HTML selectors
Normalizer
- standardize price, currency, availability, brand
Database
- save current product state
- track changes over time
9) Practical extraction order
When processing a product page, try in this order:
- JSON-LD
- Microdata
- Meta tags
- Common DOM selectors
- Fallback heuristics
This gives you the highest success rate with minimal site-specific code.
10) Example workflow
- Seed crawler with sitemap/category URLs for each domain
- Crawl listing pages and collect product links
- Visit each product page
- Extract JSON-LD product schema
- If missing, fall back to site-specific selectors
- Store normalized product record
- Re-crawl periodically to detect price/stock changes
11) Minimal Python example
A simple static-page extractor:
import requests
from bs4 import BeautifulSoup
import json
url = "https://example.com/product/123"
html = requests.get(url, headers={"User-Agent": "MyCrawler/1.0"}).text
soup = BeautifulSoup(html, "html.parser")
# Try JSON-LD
for script in soup.find_all("script", type="application/ld+json"):
try:
data = json.loads(script.string or script.get_text())
print(data)
except Exception:
pass
This is just a starting point; in real use you’d:
- handle multiple JSON-LD blocks
- normalize arrays
- extract fields from
Productobjects - add retries and rate limiting
12) What makes this hard at scale
Challenges you’ll run into:
- inconsistent HTML across sites
- anti-bot measures
- JS rendering
- geo-based pricing
- variants (size/color)
- currency differences
- product availability changes
- redirects and canonical URLs
- duplicate product pages
Plan for these early.
13) Best practice recommendation
If you want to crawl across many ecommerce sites reliably:
- Use sitemaps and structured data wherever possible
- Build a generic extractor
- Add domain-specific overrides
- Use Playwright only for the sites that require it
- Maintain a URL deduplication and normalization layer
- Store raw HTML + parsed data for debugging and reprocessing
If you want, I can also give you:
- a Scrapy project structure for multi-site product crawling,
- a Playwright + Python example, or
- a schema for normalized product data.