Introduction to Web Scraping Ethics & robots.txt
flowchart TD
A["you want data from a site"] --> B{"is there an API?"}
B -->|yes| C["use it -- stable, documented, allowed"]
B -->|no| D["read /robots.txt"]
D --> E{"is the path disallowed?"}
E -->|yes| F["do not scrape it"]
E -->|no| G["check the terms of service"]
G --> H["identify yourself in the User-Agent"]
H --> I["rate limit -- one request at a time, with a delay"]
I --> J["cache responses so a re-run does not re-fetch"]
J --> K["stop on 429 or 403 and back off"]
Scraping principles
Section titled “Scraping principles”- Prefer official APIs when available
- Respect Terms of Service
- Rate-limit requests
- Identify your scraper (User-Agent)
- Don’t scrape private data
robots.txt basics
Section titled “robots.txt basics”robots.txt is a convention that tells crawlers which paths are allowed/disallowed.
It’s not a security feature, but a strong signal.
Rate limiting
Section titled “Rate limiting”Use delays and backoff:
import time
import random
def polite_sleep(base=1.0):
time.sleep(base + random.random())Avoid getting blocked
Section titled “Avoid getting blocked”- keep concurrency low
- cache responses
- handle 429/503
- rotate proxies only if permitted and ethical
pch.coffeeTagline
pch.coffeeCtapch.feedbackHeading
pch.feedbackSubheading