Web scraping best practices are the habits that let you collect public data reliably for years instead of days: crawling slowly, reading robots.txt, identifying your bot, caching what you already have and using official APIs when they exist. Most scrapers that get blocked are not blocked because of the technique. They are blocked because they behave in ways no site owner would accept from any visitor.
The quick answer: to collect data without getting blocked, make your scraper look and act like a considerate, identifiable client. Check for an API or feed first, follow robots.txt, limit your request rate and back off when the server signals strain, cache pages and only re-fetch what changed, and monitor your output so you notice problems early. Proxies help with geography and reliability, but they are not a way around a site that has asked you to stop.
This guide covers each of those practices in turn, with web scraping tips for planning, JavaScript-heavy pages, monitoring and legal checks. It stays at the level of responsible web scraping: there are no instructions here for defeating a particular site’s bot protection or solving CAPTCHAs, because that is where technical risk becomes legal risk. If you are just getting started, our beginner’s guide to web scraping explains the basics.
Understanding the site owner’s point of view explains almost every best practice that follows. Websites block automated traffic for a few concrete reasons:
You can address the first three entirely through how you build your crawler. The fourth is a business and legal question, and the right answer is sometimes to license the data or leave the site alone.
| Practice | Why it matters | How to apply it |
|---|---|---|
| Use APIs and feeds first | Stable, permitted, cheaper to maintain | Check developer docs, sitemaps, RSS, open data portals |
| Respect robots.txt | Shows the owner’s stated wishes | Parse it before crawling, re-check at least daily |
| Limit your rate | Protects the site and your access | Concurrency caps per domain, delays between requests |
| Back off on errors | 429 and 503 mean slow down | Exponential backoff, honor Retry-After |
| Identify your bot | Lets owners contact you instead of blocking | Descriptive user agent with a URL or email |
| Cache and fetch only changes | Fewer requests, fresher data | Conditional requests, sitemaps with lastmod |
| Render JavaScript only when needed | Headless browsers are heavy | Look for the underlying JSON first |
| Monitor quality | Silent breakage corrupts datasets | Schema checks, volume alerts, sample reviews |
| Check the legal position | Public is not the same as permitted | Terms, personal data, copyright review |
The most reliable scraper is the one you never have to write. Before building anything, check whether the data is already offered in a structured form:
APIs come with documented rate limits and terms, return clean data and rarely break when a page is redesigned. Even if an API covers only part of what you need, using it for that part reduces the load and the risk of the rest of the project.
Good scrapers are designed, not improvised. Write down a short plan before the first request:
The robots.txt file at the root of a domain tells automated clients which paths they may crawl. It was formalized by the IETF as RFC 9309 in 2022, and a few details from the standard are worth building into your code:
robots.txt is not an access control system, and it does not settle every legal question, but it is the clearest statement of what a site owner wants. Ignoring it is the fastest way to turn a tolerated crawler into a blocked one.
Request rate is the practice that matters most for staying unblocked. A scraper that sends a few requests per second to a large site will usually go unnoticed. The same scraper running 200 concurrent connections against a small store can take it offline.
If a site responds with a block page or 403 Forbidden after you have done all of this, take it as a decision, not a puzzle. Contact the owner, look for a licensed source, or remove the site from your crawl.
A transparent user agent string is one of the simplest ethical web scraping practices and one of the most effective. Include your organization or bot name and a URL or email address where a site owner can reach you, for example a short page explaining what your crawler collects and how to opt out.
Site administrators who can see who you are and why you are crawling often choose to rate-limit or contact you rather than block you outright. Disguising a bot as a consumer browser has the opposite effect: once it is detected, it looks deceptive, and deception is what turns a technical dispute into a legal one.
The cheapest request is the one you do not send. Store raw responses with a timestamp so you can re-parse them when your extraction logic changes, instead of crawling the site again. For pages you revisit, use HTTP conditional requests: send the ETag value in an If-None-Match header, or the last fetch time in If-Modified-Since, and a well-configured server will reply with a short 304 Not Modified when nothing has changed.
XML sitemaps often include a lastmod date for each URL. Reading the sitemap first and fetching only URLs that changed since your last run can reduce request volume dramatically on large catalogs.
Many modern sites render content in the browser with JavaScript, so a plain HTTP request returns an almost empty page. Headless browsers such as Playwright or Puppeteer load and run the page like a real browser, which solves the problem but costs far more CPU, memory and bandwidth per page.
Before reaching for a headless browser, open your browser’s developer tools and check the network tab. Many pages load their data from a JSON endpoint you can request directly, which is lighter for both you and the site. When you do need a browser, block images, fonts and ads you do not need, reuse browser contexts and keep the same rate limits you would use for plain requests. Our list of web scraping APIs for JavaScript-rendered sites covers managed options if you would rather not run browsers yourself.
A proxy routes your requests through another IP address. In data collection, proxies have legitimate jobs: seeing the prices, search results or ads that users in a specific country or city see, spreading a large but polite crawl across infrastructure so no single connection carries all the traffic, and keeping collection running when one network path fails. Rotating sessions, where requests are distributed across a pool of addresses, is a common general pattern for those goals.
What proxies should not be used for is ignoring a site that has told you to stop. If you are blocked after respecting robots.txt and rate limits, switching IP addresses to keep going turns a technical signal into a deliberate workaround, and recent US litigation over getting around access controls shows that courts take that seriously.
Where you get proxies also matters. Residential proxy networks route traffic through real consumer devices, so ask any provider how those devices joined the network and whether their owners gave informed consent. Reputable vendors publish their IP sourcing policies; avoid free proxy lists and any provider linked to malware or botnet-sourced addresses. Our roundup of proxy-backed data extraction services is a starting point for comparing managed options.
Scrapers fail quietly. A redesigned page can turn every price into an empty string without a single error in your logs. Treat your scraper as a data pipeline and monitor it like one:
For larger programs, it is often cheaper to buy this layer than to build it. Our guides to web scraping tools for data extraction and cloud-based scraping tools for ecommerce monitoring compare services that include scheduling, monitoring and data delivery.
Technical politeness does not make every project lawful. Before you scale up, run through a short legal review, and get proper advice for anything sensitive:
This section is general information, not legal advice.
If you searched for how to avoid getting blocked web scraping, the honest answer is less exciting than most tutorials suggest. Sites block scrapers that are fast, anonymous and careless. Slow down, identify yourself, cache aggressively, fetch only what changed, use APIs where they exist and stop when a site says no. Those habits solve the large majority of blocking problems without any tricks, and they keep you on the right side of both the site owner and the law.
There is no universal number. A large retailer’s infrastructure can absorb far more than a small business site. Start low, around one request every few seconds per domain, honor any Crawl-delay, and adjust based on response times and error rates. If latency rises or you see 429 or 503 responses, slow down.
In most countries robots.txt is not legally binding on its own, but it is the clearest expression of what a site owner wants, and courts and regulators increasingly treat it as relevant. Following it is a core part of responsible web scraping and one of the best ways to avoid being blocked.
No. Rotating fake browser user agents to disguise a bot works against you. A single, honest user agent that names your crawler and gives contact details is the better long-term approach, because it gives site owners a reason to talk to you instead of blocking you.
Only when the data you need is rendered by JavaScript and is not available from an underlying JSON endpoint, feed or API. Headless browsers are heavier for you and the site, so check the network requests first and keep the same rate limits when you do use one.
Building gives you full control and suits small, stable projects. A managed scraping API or data provider makes sense when you need many sites, JavaScript rendering, geographic coverage or monitoring at scale. In both cases, the same best practices on rate, respect for robots.txt and data scope still apply.
Web Scraping Best Practices: How To Collect Data Without Getting Blocked comes down to a simple idea: behave like a visitor the site owner would be happy to have. Use official APIs and feeds where they exist, read robots.txt, limit your rate and back off when asked, identify your bot, cache and fetch only what changed, render JavaScript only when you must, and monitor your data as carefully as you collect it. Add a legal check before you scale, and treat a block as a message rather than a challenge. Follow these web scraping best practices and your data pipeline will be more reliable, cheaper to run and far easier to defend.