Amazon Product Details Scraper
This script helps you scrape product details from Amazon product pages. It extracts information like title, description, and image URLs, saving them to JSON files.
Features
- Fetches product details from a single Amazon product URL or a list of URLs in a file.
- Writes extracted data to JSON files for easy storage and processing.
- Optionally downloads product images along with details.
Installation
Requirements:
- Python 3 (tested with 3.7+)
- Libraries:
- requests
- beautifulsoup4
- urllib3
Instructions:
-
Make sure you have Python 3 installed. You can check by running
python3 --versionin your terminal. -
Create a virtual environment (recommended):
-
Virtual environments help isolate project dependencies and avoid conflicts with other Python installations on your system.
-
Here's how to create a virtual environment using
venv:python3 -m venv my_env # Replace "my_env" with your desired environment name
-
Activate the virtual environment:
source my_env/bin/activate
-
-
Install:
python3 setup.py install
This will automatically download and install the necessary libraries based on the specifications within the activated virtual environment.
Usage
Basic Usage:
amazon-scraper --url https://www.amazon.com/product-1 # Replace with your product URL
This will scrape details from the provided Amazon product URL and write them to a JSON file in the "output" directory (default).
Using a URL List:
- Create a text file containing a list of Amazon product URLs (one per line).
- Run the script with the
--url-listoption and provide the file path:
amazon-scraper --url-list product_urls.txt
This will process each URL in the file and save the scraped details for each product in separate directories within "output".
Optional: Downloading Images:
amazon-scraper --url https://www.amazon.com/product-1 --download-image
The --download-image flag enables downloading product images along with other details.
Getting Help:
The script offers a built-in help message that provides a quick overview of available options and usage instructions. To access the help, run the script with the --help option:
amazon_scraper --help
Configuration
Logging:
- The script uses basic logging for information and error messages.
- You can modify the logging level by editing the
DEFAULT_LOG_LEVELinconfig.pyline in the code (refer to the Python documentation for logging configuration).
Example
Scenario:
Scrape details for two products from a file named "products.txt" and download images:
-
Create a file named "products.txt" with the following content:
https://www.amazon.com/product-1 https://www.amazon.com/product-2 -
Run the script with the following command:
amazon-scraper --url-list products.txt --download-image
This will process both URLs in the file, scrape details, create separate output directories for each product, and download images.
Disclaimer
This script is for educational purposes only. Please be respectful of Amazon's terms of service when using it. Consider using official APIs provided by Amazon for extensive data collection.
Metadata
Release files for amazon-product-details-scraper 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| amazon_product_details_scraper-1.0.5.tar.gz | 9.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| amazon_product_details_scraper-1.0.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.7 kB
Release files / amazon_product_details_scraper-1.0.5.tar.gz
| Download URL | amazon_product_details_scraper-1.0.5.tar.gz |
|---|---|
| Size | 9.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2e85df1543b404aca7b2b7eb01353acd52a59f27d1436e3d8b3c3797d94a7b80
|
|
BLAKE2b-256 checksum How to use checksums |
ba01bde37542278ddbd3bf63e8bf28950c213bd730f4b10787c1377abe610c56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / amazon_product_details_scraper-1.0.5-py3-none-any.whl
| Download URL | amazon_product_details_scraper-1.0.5-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4efaef5d597dc1f5b6bfe81a15c4822adecaef2c647e4827360684bbfdd808d1
|
|
BLAKE2b-256 checksum How to use checksums |
a4b72f4082066c9110711e2d0ca9b9d221d6d7fd3c00a6c24c26bcd627f51e15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|