If you have ever spent an afternoon copying a product table off a website row by row, this is the fix.
You only need two libraries: requests to fetch the page, and BeautifulSoup to pull the table out. Find the table, loop over its rows, write each row to a CSV file — that is genuinely most of the job for public, static pages.
The whole script
import csv import requests from bs4 import BeautifulSoup HEADERS = {"User-Agent": "Mozilla/5.0 (compatible; StarterKitBot/1.0)"} def table_to_csv(url, output_path, table_index=0): response = requests.get(url, headers=HEADERS, timeout=15) response.raise_for_status() soup = BeautifulSoup(response.text, "lxml") tables = soup.find_all("table") if not tables: print("No <table> found. The data might be loaded by JavaScript.") return rows = [] for tr in tables[table_index].find_all("tr"): cells = tr.find_all(["th", "td"]) rows.append([cell.get_text(" ", strip=True) for cell in cells]) with open(output_path, "w", newline="", encoding="utf-8") as f: csv.writer(f).writerows(rows) print(f"Saved {len(rows)} rows to {output_path}") table_to_csv("https://example.com/prices", "prices.csv") Run it:
pip install requests beautifulsoup4 lxml python table_to_csv.py Open prices.csv in Excel or Google Sheets and you are done.
The parts that actually trip people up
The scraping itself is the easy part. The things that eat your afternoon are:
- Pagination — the data you want is spread across 20 pages, and each page needs the same treatment.
- Cleaning the output — merged cells, stray whitespace, prices stored as text with currency symbols.
- Picking the right table — pages often have more than one
<table>. The--indexflag in the full version lets you choose which one. - JavaScript-loaded pages — if
find_all("table")comes back empty, the table probably renders in the browser after load, andrequestsalone will not see it.
A polite User-Agent, a short delay between pages, and a quick look at the site's robots.txt keep you out of most trouble on public pages.
Where this goes next
The full version of this script (with the --index flag and proper error messages) is free on my GitHub: https://github.com/luciusdata/table-to-csv
I packaged the versions I actually reuse — table-to-CSV, multi-page listings, product prices, business contacts, a sitemap sweep, JSON API-to-CSV, and a CSV cleaner — into a small starter kit with a plain-English guide. It is $3 while the store is new: https://luciusdata.gumroad.com/l/sbpiem
Happy to answer questions about the approach in the comments, whether you grab the kit or not.

