How oriartyz/amazon_scrapper works
Project Type and Purpose
• This is a web scraping application that leverages the Flask framework to provide a simple user interface for scraping product data from Amazon (including product name, price, image, and description).
• The README and file tree indicate that it is a full-stack-like application: the backend handles scraping logic and HTTP requests, and the frontend is composed of HTML templates with static assets (CSS).
Main Components
a. User Interface (Frontend):
• HTML Templates: Represented by the files in the "templates" directory (search.html and results.html) which provide the UI screens.
• Static Assets: Located in the "static" directory (styles.css, and any additional assets like images if needed) that support the styling of the web pages.
b. Flask Application (Backend Server):
• Core Application: The app.py file that initializes and runs the Flask web server, routes user requests, and integrates with the scraping logic.
c. Scraping Logic Module:
• amazon_products.py: Contains the core functionality for sending HTTP requests (using Flask internally to trigger these actions), parsing web pages with BeautifulSoup, and extracting product data.
• Dependencies: Represent the use of external libraries such as BeautifulSoup, Requests, and Flask that are crucial for the scraping and web operations.
d. Data Store / Logging:
• CSV File: The "price_change.csv" file is used (or could be used) for persisting product price changes or historical data related to the scraping results.
e. Deployment & Configuration:
• Procfile: Indicates deployment configuration (common for platforms like Heroku) that outlines which command runs the web app.
• requirements.txt: A list of all dependencies required for the project, ensuring environment consistency.
Relationships and Interactions
• The User (browser) interacts with the Flask application by accessing the web pages rendered from the HTML templates.
• When a search or scraping request is made, app.py routes the request to a controller which then calls functions in amazon_products.py.
• The scraping module makes outbound requests to the Amazon site, processes the HTML response (using BeautifulSoup), and returns structured data.
• The returned data is then potentially written into a CSV (price_change.csv) for persistence or logging, and passed to the templates for user display.
• Deployment is managed via the Procfile for a cloud hosting platform.
Important Architectural Patterns and Design Principles
• Separation of Concerns: The project is cleanly split between the presentation layer (frontend HTML/CSS), and the backend that handles both the web server (Flask) and business logic (scraping in amazon_products.py).
• Lightweight Web Framework: Flask is used for quick development, routing, and templating.
• Modularity: The scraping functionality is modularized (amazon_products.py) for isolation and easier maintenance.
• Data Logging/Persistence: Storing price changes in a CSV demonstrates a simple form of state persistence or logging.