This project is a FastAPI-based web API that scrapes product data from Amazon using Selenium and stores it in a MySQL database. It allows users to add, update, retrieve, and delete product records via HTTP endpoints.
β οΈ Note: This project is for educational purposes only. Frequent scraping of Amazon may violate their Terms of Service.
- Scrape Amazon product details using a provided product URL.
- Extracted fields include:
- Product title
- Price
- Image URL
- Store product data in a MySQL database.
- Perform CRUD operations via RESTful endpoints:
- Add new product
- Fetch all or specific product
- Update individual or all product prices
- Delete product by ID
Amazon-Web-Scraper-API/
β
βββ amazon/
β βββ products.py # Core logic for scraping product data using Selenium
β
βββ app/
β βββ main.py # FastAPI application with all API routes
β
βββ database/
β βββ models.py # SQLAlchemy models for Products table
β βββ schemas.py # Database connection and session logic
β
βββ .gitignore
βββ requirements.txt
βββ README.md
βββ credentials.env # Environment variables (ignored in git)
Install dependencies using pip:
pip install -r requirements.txtEnsure you have MySQL running and a database created. Store your credentials in a credentials.env file like this:
_USERNAME=your_username
_PASSWORD=your_password
_HOST=localhost
_PORT=3306
_DATABASE=your_database_name-
Create the database schema:
from database.models import create_all create_all()
-
Start the FastAPI server:
uvicorn app.main:app --reload
-
Use the API endpoints:
- Add product by scraping:
POST /products/add?url={amazon_product_url}&target={target_price} - Fetch all products:
GET /products - Fetch specific product:
GET /products/{product_id} - Update all products:
PUT /products/update - Update specific product:
PUT /products/update/{product_id} - Delete a product:
DELETE /products/delete/{product_id}
- Add product by scraping:
- Python
- FastAPI
- Selenium
- SQLAlchemy
- MySQL
- Uvicorn
- Python-dotenv