Skip to content

About

Python web scraper that turns paginated catalog/listing sites into clean Excel/CSV spreadsheets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

CatalogScraper

tests license

Turns a paginated product or listing site into a clean spreadsheet — crawl, extract, paginate, export. A new site is a new YAML file, not a code change.

pip install -e .
python -m catalog_scraper --config sites/books_toscrape.yaml --out ./out
Crawling books.toscrape.com ...
  page 1: 20 items
  page 2: 20 items
  page 3: 20 items
Collected 60 items.
Saved: out/books_toscrape_com.csv
Saved: out/books_toscrape_com.xlsx
title price_gbp rating in_stock product_url
A Light in the Attic 51.77 3 True .../a-light-in-the-attic_1000/index.html
Tipping the Velvet 53.74 1 True .../tipping-the-velvet_999/index.html

The demo target is books.toscrape.com, a public sandbox built specifically for scraping practice.

Pointing it at a different site

Copy sites/books_toscrape.yaml, change the selectors, run it. Nothing in catalog_scraper/ needs editing.

name: example-shop
start_url: https://example.com/products?page=1
base_url: https://example.com/

item_selector: .product-card          # one match per item on the listing page
next_page_selector: a.pagination-next # omit to scrape a single page

delay_seconds: 0.5
max_pages: 10                         # omit for the whole catalog

fields:                               # each key becomes a spreadsheet column
  title:
    selector: .product-card__name
  price:
    selector: .price
    transform: money                  # "£51.77" -> 51.77
  in_stock:
    selector: .availability
    transform: in_stock               # "In stock (5)" -> True
  url:
    selector: a.product-link
    attr: href                        # read an attribute instead of the text
    transform: url                    # resolved to an absolute URL

Available transforms: text (default), money, int, star_rating, in_stock, url. Adding one is a function in catalog_scraper/parser.py plus an entry in TRANSFORMS — still no per-site branching.

What it handles

  • Pagination — follows next_page_selector to the end, or stops at max_pages
  • Loop protection — a site whose "next" points back at the current page ends the crawl instead of spinning forever
  • Relative links — resolved against base_url, so exported URLs are clickable
  • Missing fields — a selector that matches nothing yields an empty cell rather than crashing the run
  • Excel-friendly output — UTF-8 with BOM so Windows Excel keeps accents, numbers stay numeric, header row frozen
  • Politeness — custom User-Agent and a configurable delay between requests

CLI

--config PATH      site config to use (required)
--out DIR          output directory (default: current)
--name STEM        output filename stem (default: derived from the config name)
--max-pages N      stop after N pages, overriding the config
--csv-only         skip the .xlsx export

Layout

catalog_scraper/
  config.py      load and validate a site config
  parser.py      listing HTML -> rows; the transform registry lives here
  crawler.py     page-by-page loop, injectable fetcher and sleep
  exporters.py   CSV and XLSX writers
sites/           one YAML per target site
tests/           28 tests, offline

Tests

pip install -e ".[dev]"
pytest

No network access. Parsing is checked against a saved copy of a real listing page in tests/fixtures/, and the crawl loop runs against an injected fetcher — so the suite is deterministic and safe to run in CI.

Requirements

Python 3.10+ · requests · BeautifulSoup · openpyxl · PyYAML

License

MIT — see LICENSE.

About

Python web scraper that turns paginated catalog/listing sites into clean Excel/CSV spreadsheets

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages