Most scrapers work on day one and quietly break by week three. A class name changes, a “Load more” button replaces pagination, or the site starts returning 429s. These are the rules behind the open-source ScrapeMaster series and the production scrapers we build, written so your next scraper keeps running long after the demo.
1. Look for an API before you scrape
Open your browser’s developer tools, go to the Network tab, filter by Fetch/XHR and reload the page. Many modern sites load their data from a JSON endpoint, which is faster, cleaner and far more stable than parsing HTML. Also check for an official API, a sitemap or an RSS feed. The best scraper is the one you don’t have to write.
2. Start with plain HTTP, use a browser only when you must
requests plus BeautifulSoup is dozens of times cheaper and faster than a headless browser. Reach for Playwright or Selenium only when the content is rendered by JavaScript, sits behind a login, or needs interaction like scrolling and clicking. A good test: if the data is visible in “View source”, you don’t need a browser.
3. Prefer stable selectors, or let an LLM read the page
Auto-generated class names like css-1x2y3z change with every deploy. Anchor on things that rarely change: data-* attributes, semantic tags, ARIA labels or visible text. When layouts vary a lot between sites, an LLM with a strict output schema can replace selectors entirely. Convert the HTML to Markdown first to cut tokens and noise, the approach ScrapeMaster uses:
from pydantic import BaseModelfrom openai import OpenAIclass Listing(BaseModel):title: strprice: float | Noneurl: strclass Page(BaseModel):listings: list[Listing]client = OpenAI()markdown = html_to_markdown(html) # strip scripts, styles and boilerplate firstresult = client.beta.chat.completions.parse(model="gpt-4o-mini",messages=[{"role": "system", "content": "Extract every product listing on the page."},{"role": "user", "content": markdown},],response_format=Page,)listings = result.choices[0].message.parsed.listings
4. Handle pagination deliberately
Identify which pattern you are dealing with: page numbers in the URL, a “next” link, a cursor-based API or infinite scroll. Then define a clear stop condition (no next link, an empty page, or a repeated item) and deduplicate on a stable key. Unbounded pagination loops are the most common cause of runaway scrapers.
5. Be polite: throttle, back off and cache
Space out your requests, honor Retry-After headers, back off exponentially on 429 and 503 responses, and cache pages you have already fetched. Check robots.txt and run large jobs off-peak. Polite scrapers get blocked far less and put less load on the sites you depend on.
import random, time, requestsdef fetch(url, session, max_retries=5):for attempt in range(max_retries):r = session.get(url, timeout=30)if r.status_code in (429, 503):# Respect Retry-After when present, otherwise back off exponentiallywait = float(r.headers.get("Retry-After", 2 ** attempt))time.sleep(wait + random.uniform(0, 1))continuer.raise_for_status()return rraise RuntimeError(f"Gave up on {url}")
6. Treat blocks and captchas as a signal
If a site actively blocks automated access, that is information. Consider asking for API access or a data partnership. For legitimate workflows that hit an occasional captcha or login step, a human-in-the-loop attended mode works well: a person solves the challenge, then the scraper takes over. That is exactly what ScrapeMaster 4.0 introduced.
7. Validate the data, not just the run
A scraper that “succeeds” while returning empty prices is worse than one that crashes. Validate every record against a schema, track null rates and row counts per run, and flag anomalies such as a 90% drop in results or prices that suddenly read zero.
8. Store the raw HTML next to the parsed data
Keep a compressed copy of each page you parse. When your parser changes, or you realize you need one more field, you can reprocess everything without hitting the site again. It also makes debugging a broken run a five-minute job.
9. Monitor, because scrapers fail silently
Log the number of pages fetched, records extracted and errors for every run, and alert when a run returns zero rows or takes far longer than usual. Scheduling your scraper in n8n gives you retries, logs and Slack or email alerts almost for free.
10. Stay on the right side of the law
Collecting publicly available data is generally lawful, but terms of service, copyright and data-protection rules still apply. In the EU, GDPR covers any personal data you collect, so avoid it unless you have a lawful basis. When in doubt, ask a lawyer. This guide is not legal advice.
Where to go from here
Want to see these ideas in code? Walk through the four ScrapeMaster versions, from a single-URL extractor to pagination, multi-site runs and attended mode. And if you need a scraper that runs on a schedule and delivers clean data to your tools, that’s what our web scraping service is for.