Web Scraping
Web scraping is how I automate collecting public data from websites — SERPs, competitor pages, product catalogs — and dump it into a CSV or JSON for analysis. It's not crawling, it's not copy-pasting, and it's not always legal.
What I’d do first
- Always check robots.txt and terms of service first.
- Start with one page and a simple selector before scaling.
- Respect rate limits — add delays and rotate user agents.
- Store output as CSV or JSON for easy analysis.
- Stop if you hit aggressive anti-bot or login walls.
The first time I tried scraping a major e-commerce site, I got blocked within 12 requests. I learned the hard way that preparation matters more than the scraping code itself.
The path I'd take
Here's the step-by-step I follow for a typical scrape — say, pulling product titles and prices from a category page:
- Start with one page. I write a simple script using Python's
requestsandBeautifulSoup(or Node'saxiosandcheerio). I fetch the HTML, parse it, and extract the data using the selector I found earlier. I print it to the console first to verify it works. - Handle pagination. Most category pages have a "next" button or a page number in the URL. I look for the pattern — often
?page=2— and loop through pages. I add a delay between requests (usually 2-5 seconds) to avoid hammering the server. - Store the output. I write the data to a CSV file. I keep it simple: headers like
title, price, url. No databases yet. CSV is universal and I can open it in Excel or load it into a tool like Google Sheets. - Add error handling. Websites break. I wrap requests in try/except blocks, log failed URLs, and retry once after a longer delay. If a page returns a 403 or 429, I stop and check if I'm being blocked.
- Scale carefully. Once the script works for 10 pages, I run it for 100. I monitor the response codes. If I see a pattern of 403s, I rotate user agents or use a proxy. But honestly, for most SEO tasks, you don't need thousands of pages — a few hundred is usually enough.
Watch-outs
A few things that have tripped me up:
- JavaScript-rendered content. If the data you want is loaded after the page loads (like a price that appears after a script runs),
requestswon't see it. You need a headless browser. I've used Puppeteer for this, but it's slow. Sometimes the data is available in a hidden API call — check the Network tab in DevTools. - Rate limiting. Some sites block you after a certain number of requests per minute. I've had to add random delays (between 1 and 3 seconds) to avoid triggering it. If you're scraping a small site, be extra gentle.
- Changing HTML structure. Sites redesign. Your selectors break. I've had scrapes that worked for months suddenly fail because a class name changed. I now log the raw HTML of failed pages to debug quickly.
- Legal grey areas. Even if robots.txt allows it, some data is copyrighted (like full article text). I only scrape what I need — headlines, prices, meta descriptions — not entire pages.
When to stop
I stop scraping when:
- The site returns consistent 403 or 429 errors. It's not worth fighting aggressive anti-bot systems. Find another source or use an API.
- The data is behind a login. I don't scrape authenticated content — it's almost always against terms and potentially illegal.
- The site explicitly says "no scraping" in its terms. I respect that. There are plenty of other data sources.
- The data quality is poor. If the HTML is so messy that parsing takes longer than manual collection, I reconsider the approach.
Next step
Quick answers
Is web scraping legal?
It depends. Scraping public data for personal use is often legal, but violating terms of service, bypassing authentication, or copying copyrighted content can get you in trouble. I always check robots.txt and local laws first.
What's the difference between web scraping and web crawling?
Crawling discovers and indexes URLs (like Googlebot). Scraping extracts specific data from pages. You can crawl without scraping, but you usually scrape after you've crawled.
Sources
Primary documentation is linked directly. Anything commercial is marked nofollow.
- Google Search Central — Best source for Google's guidance on crawling, indexing, and site access rules.
- RFC 9309: Robots Exclusion Protocol — The authoritative standard for robots.txt behavior.
- Cloudflare bot management resources — Useful for understanding anti-bot detection and scraping blockers.
Notes from Callum Bennett.