Projects · 03/06

Projects

Books scraper and analysis

A polite scraper that walks all 1000 books on books.toscrape.com into a clean CSV, then a pandas + matplotlib analysis asking whether higher-rated books cost more. They do not: r is about 0.03.

cd ..back to projects

Overview

scrape.py follows the next link across 50 listing pages and visits every detail page for category and stock count, fields that only exist there. Prices and star ratings are parsed with small, unit-tested helpers. Each request waits 0.5 s, times out at 15 s and retries up to three times with backoff; a broken book page yields None fields instead of a crash. When the run ends, the row count is checked against the total printed on the site. analiz.py produces three charts and a written answer. The project was built alongside Claude Code with a rule file, a prompt log and a reflection report committed to the repo.

Highlights

  • Three test layers: unit parsers with no network, integration against the live site, and an end-to-end run through a temporary directory.
  • Ethical defaults: identifying User-Agent, enforced minimum delay, no parallel requests.
  • Paths resolve relative to the script, so it runs from any working directory and creates its own output folders.

Figures

Bar chart of the ten most expensive book categories by average price
Average price per category, limited to categories with at least two books.
Bar chart showing how many books received each star rating from one to five
Distribution of star ratings across 1000 books.
Box plot of book prices grouped by star rating
Price by rating with Pearson correlation: essentially flat.