Scraping is often the only way to collect data a site doesn't offer any other way. It's also fragile: a redesign can break a scraper overnight. These habits make scrapers last longer and fail loudly when they do break.
Look for the data before scraping the page
Open the browser's network tab. Many modern sites load their content from a JSON endpoint, which is far more stable than the HTML around it. Check for an official API or a data export too.
Choose selectors that survive redesigns
- Prefer meaningful attributes (
data-testid,itemprop,aria-label) over long CSS paths likediv > div:nth-child(3) > span. - Anchor on visible labels ("Price") rather than position.
- Keep all selectors in one place so a site change is a one-file fix.
Validate every record
Check each scraped item against what you expect: price is a positive number, date parses, required fields aren't empty. If more than a small share of records fail, stop the run and alert someone. A scraper that silently returns empty fields is worse than one that crashes.
Be polite
- Read the site's terms and
robots.txt, and respect them. - Limit your request rate and add delays between pages.
- Set a clear User-Agent and cache pages you've already fetched.
- Scrape during quiet hours where you can.
Handle JavaScript-heavy sites last
Tools like Playwright can drive a real browser, but they're slower and heavier. Use them only when the data truly isn't available in the HTML or an underlying request.
Store the raw page
Save the HTML or JSON you fetched along with the parsed result. When parsing breaks, you can fix the parser and re-run it on stored pages without scraping again.

Comments (0)
No comments yet. Start the conversation.
Join the conversation
Sign in or create a free account to comment.