1
Step 4 Scraper
Tirsvad edited this page 2026-11-21 07:57:32 +01:00

Step 4: Scraper

🌐 English · Dansk · Bahasa Melayu

Milestone MIL-004. Branch and pull request: one for this step.

Scraper tests with 99 % coverage

What was done

The infrastructure layer: a polite web client that reads robots.txt first, refuses disallowed paths, sends an honest User-Agent, waits between requests and retries a failed request a limited number of times; a parser for ranking pages and one for food pages, both built on html.parser; and unit tests that use small HTML fixtures and a fake transport, so no test touches the network.

What was gained

  • urllib.robotparser answers "may I fetch this?" in one call, and checking it before every request is cheap politeness.
  • html.parser is event based: the parser keeps a small state (inside a table row, inside the first cell) instead of searching a tree, which is why the fixtures matter.
  • Injecting the transport and the clock makes the delay and the retries testable in milliseconds.