BookScraper is a Python command-line tool that scrapes book titles and prices from Books to Scrape. It allows you to fetch books from a specific category and save the results in a well-formatted text file or a structured JSON file.
- Scrapes book titles and prices by category
- Uses
requests
,BeautifulSoup
,re
, andtabulate
for web scraping and formatting - Saves results in either
.txt
(pretty table) or.json
format - User-friendly and interactive command-line interface
- Supports UTF-8 encoding for file outputs
Make sure you have Python 3.6+ installed. Then, install the required libraries:
pip install requests beautifulsoup4 tabulate
Run the script in your terminal:
python book_scraper.py
You will be prompted to:
- Enter the book category you want to scrape (e.g.,
travel
,humor
,novels
, etc.). - Choose whether to save the results as a
.txt
file. - Choose whether to save the results as a
.json
file.
-
If the category name has two words, use a dash - between them. Example:
- β science-fiction
- β historical-fiction
-
The category name must exist on Books to Scrape.
-
Important: You must set your own User-Agent inside the script before running it.
To do this, replace theuser-agent
field inside theheaders
dictionary with your real browser's User-Agent string.
Example:
headers = {
'user-agent': 'your actual User-Agent here'
}
Tip: To find your User-Agent, you can visit https://www.whatismybrowser.com/ and copy the string.
- The script will not work without a valid User-Agent.
Type: travel
Date: 27/04/2025
================================================
ββββββββββββββββββββββββββββββββββ€βββββββββββββ
β Title β Price β
ββββββββββββββββββββββββββββββββββͺβββββββββββββ‘
β It's Only the Himalayas β Β£45.17 β
β Full Moon over Noah's Ark β Β£49.43 β
β See America: A Celebration... β Β£48.87 β
ββββββββββββββββββββββββββββββββββ§βββββββββββββ
[
{ "Title": "It's Only the Himalayas", "Price": "Β£45.17" },
{ "Title": "Full Moon over Noah's Ark", "Price": "Β£49.43" },
{ "Title": "See America: A Celebration...", "Price": "Β£48.87" }
]
This project is licensed under the MIT License. See the LICENSE file for details.