Two Python scripts that scrape data from books.toscrape.com and quotes.toscrape.com and save the results as CSV files.
- Books scraper (
books_scraper.py) – collects book titles, prices (cleaned), ratings, links, and availability from all pages of the site. - Quotes scraper (
quotes_scrapper.py) – collects quotes, authors, and links to author detail pages. - Progress output – prints the URL being scraped.
- Error handling – timeouts and request exceptions are caught.
- CSV export – results are saved to
Books.csvandquotes_all.csv.
- Install required packages:
pip install requests beautifulsoup4 lxml
- Run the scraper:
- For books:
python books_scraper.py
- For quotes:
python quotes_scrapper.py
- For books:
- The scraped data will be saved in the same folder as the script.
web-scrapers/
├── books_scraper.py # Books to scrape
├── quotes_scrapper.py # Quotes to scrape
├── Books.csv # Output from books scraper
├── quotes_all.csv # Output from quotes scraper
└── README.md # This file
- Python 3
requests– HTTP requestsBeautifulSoup4– HTML parsinglxml– parser (faster than html.parser)csv– standard library for CSV writingre– regular expressions for price cleaning
Books.csv columns: ID, Title, Price (float), Rating, Link, Availability
quotes_all.csv columns: ID, Text, Author, Author_Details (URL)
- Change the
base_urlornext_urlto scrape different sections of the site. - Modify the field extraction logic in the loops to capture additional data.
For questions or suggestions:
dev.tharana@gmail.com
Built as a portfolio project to demonstrate web scraping with Python, using real test sites.