How amitchakraborty123/tecno-agricola-scraper works
1. Project type and scope
- This is a small, single-purpose Python scraping tool, not a multi-service application.
- The only external system in the architecture is the target website, tecnoagricolamodena.it, from which product catalog data is collected and exported.
2. Primary execution entry point
- src/scraper.py is the runtime entry point.
- The README shows it is run interactively from the src/ directory and prompts the user to choose between:
- scraping all categories, or
- scraping one category via a provided URL.
3. Core processing pipeline
- The app follows a straightforward flow:
1. read the user’s scraping mode,
2. determine the category URL set,
3. request category and product pages,
4. parse product data,
5. aggregate results,
6. export a CSV to output/products.csv.
- The output is tabular product data with fields like Link, Name, Price, Image, and Availability.
4. Scraping and parsing layer
- The scraper uses Python HTTP and HTML parsing libraries listed in the README: requests, beautifulsoup4, and lxml.
- This layer is responsible for downloading pages, traversing pagination, and extracting product cards/details from HTML.
5. Data transformation and export
- Product records are normalized into a structured dataset before export.
- pandas is used for the final tabular representation and CSV generation, which is the main persistence artifact of the repo.
- The repository also includes sample_output/Products_Data.csv as a reference output.
6. Configuration boundary
- src/config.py centralizes runtime settings and constants.
- The presence of .env.example suggests some settings can be externalized, even if the project is primarily file-and-CLI driven.
- This creates a clean boundary between scraping logic and environment-specific values such as paths or site-specific constants.
7. Utility/shared helpers
- src/utils.py likely contains shared support functions used by the scraper, such as formatting, URL handling, logging helpers, or file/output helpers.
- In architecture terms, this is the “support” layer beneath the main scraper workflow.
8. Reliability and operational behavior
- The README explicitly calls out session reuse, automatic retries, and logging.
- That means the scraper is designed to be resilient to transient network failures and to reuse HTTP state efficiently during long catalog crawls.
- The logs/ directory exists as a runtime artifact boundary for operational diagnostics.
9. Testing strategy
- tests/test_scraper.py validates scraper behavior using fixture HTML in tests/fixtures/sample_product.html.
- This indicates the tests are parser-centric and likely avoid live network dependency by feeding saved HTML into the scraping logic.
- The architecture therefore separates network access from HTML extraction enough to make unit testing feasible.
10. Repository output and artifact boundaries
- output/ is the active destination for generated CSVs.
- sample_output/ holds a reference dataset for expected output shape.
- screenshots/ documents the workflow visually but does not affect runtime behavior.
11. Technology stack and runtime
- The project targets Python 3.10+ and is packaged with pyproject.toml plus requirements.txt.
- Tooling includes pytest for tests and ruff/black for quality and formatting, which matters mostly for maintainability rather than runtime architecture.
12. Diagram framing
- If you draw the architecture, the main boxes are:
- User/CLI input
- scraper.py orchestration
- HTTP fetching to the external ecommerce site
- HTML parsing/extraction
- Data assembly/export via pandas
- CSV output under output/
- tests using local HTML fixtures
- The repo is essentially a linear ETL-style scraper with a thin configuration layer and a small test harness.
Main entry points: scraper.py Scraper · test_scraper.py Scraper tests · config.py Config · utils.py Utils
Components 16
Runtime
Interactive scraping workflow and core code
- User · Chooses scrape mode and provides category URL when needed
- Scraper · Main runtime entry point and crawl controller
src/scraper.py - Mode select · Determines whether to scrape all categories or one category
src/scraper.py - Catalog flow · Builds category URL set and drives pagination across product listings
src/scraper.py - HTTP fetch · Downloads category and product pages with session reuse and retries
src/scraper.py - HTML parse · Extracts product cards and product details from page HTML
src/scraper.py - Aggregate · Normalizes scraped fields into a structured product dataset
src/scraper.py - CSV export · Converts records to a dataframe and writes the final CSV
src/scraper.py
Support
Configuration and shared helpers
Testing
Unit tests and HTML fixtures
- Scraper tests · Validates scraper behavior against local fixture HTML
tests/test_scraper.py - HTML fixture · Saved product page HTML used for parser-centric testing
tests/fixtures/sample_product.html
Artifacts
Generated and reference outputs
- Output CSV · Primary generated product dataset at output/products.csv
output/.gitkeep - Sample CSV · Reference output dataset showing expected tabular shape
sample_output/Products_Data.csv - Logs · Operational diagnostics generated during scraping runs
logs/.gitkeep
External
Target website being scraped
- Tecno Agricola · External ecommerce site whose catalog pages are scraped
Connections 17
- User → Mode select: choose · User selects scraping mode and may supply a category URL
- Mode select → Config: read settings · Mode handling depends on centralized constants and paths
- Scraper → Mode select: prompt · Entry point collects interactive input
- Scraper → Catalog flow: orchestrate · Main script coordinates the crawl workflow
- Catalog flow → HTTP fetch: request pages · Catalog flow fetches listing and product pages
- HTTP fetch → Tecno Agricola: GET · HTTP requests target the ecommerce site
- Catalog flow → HTML parse: parse pages · Fetched HTML is handed to extraction logic
- HTML parse → Tecno Agricola: extract from · Parsed content originates from site HTML
- HTML parse → Aggregate: records · Extraction yields structured product fields
- Aggregate → Utils: helpers · Normalization may rely on shared helper functions
- Aggregate → CSV export: tabularize · Aggregated records are prepared for dataframe output
- CSV export → Output CSV: write · Final CSV is written to the output directory
- CSV export → Sample CSV: shape · Reference CSV reflects the expected exported schema
- Scraper → Logs: log · Operational logging is emitted during crawl runs
- Scraper tests → HTML fixture: uses · Tests load saved HTML instead of live pages
- Scraper tests → HTML parse: verify · Tests focus on parser behavior and extraction results
- Scraper tests → Scraper: exercise · Test suite covers scraper behavior through the runtime code path