Polite Scraper
You'll pull data from a public web page with a script, the way a considerate guest would, and check it by hand against the site.
About
Scraping is reading a web page with a script instead of your eyes. Done badly it gets you blocked and gives scrapers a bad name. Done well, nobody notices: you read robots.txt, send at most one request a second, identify yourself, cache everything, and stop the moment they ask. Check for an API or a download link first, because half the time the data is already on offer and nobody looked. Personal data is off the table. Public prices, schedules, listings and stats are the usual targets.
At a glance
- Per requirement
- 35 XP
- Completion bonus
- 300 XP
- Requirements
- 6
- Takes
- Two weekends
- Skill level
- Intermediate (months of practice)
- Cost
- Free
- Supplies
- Nothing special
- Where
- At home
- Other people
- On your own
Requirements
-
1
Pick a public site, read its robots.txt and terms, and write one line on whether scraping is allowed. robots.txt sits at the root of every site. If it disallows the path, or the terms forbid scraping, pick another site. Looking for an existing API or export is step zero, and if one exists, use it instead. Take a photo of your note with the robots.txt lines quoted. Photo
-
2
Fetch one page and pull three fields from it. Use requests and BeautifulSoup in Python, or curl and a parser. Save the raw HTML to disk the first time and parse from the file, so you're not hitting the site while you figure out the selectors. Take a screenshot of the three fields printed. Photo
-
3
Set a user agent with a way to contact you, and a delay of at least one second between requests. A user agent like 'name-scraper/1.0 (your email)' means a site admin can reach you instead of blocking you. Sleep between requests, every time. Take a screenshot of the code showing both. Photo
-
4
Cache responses so re-running doesn't re-fetch. Save each page by URL hash with a timestamp, and only re-fetch if it's older than a day. A scraper you run twenty times while debugging shouldn't hit the site twenty times. Take a screenshot of the cache folder. Photo
-
5
Scrape twenty pages into a CSV and spot-check five against the site by hand. Open five rows, open the five pages, and compare. Scrapers silently grab the wrong column all the time, and this is the only way to catch it. Take a screenshot of the CSV, and note any mismatches you found. Photo
-
6
Handle the day the site changes its layout. When a selector finds nothing, the script should stop and tell you rather than writing empty rows. Break the selector on purpose and show the error. Take a screenshot of the message. Photo