A Python-based scraper for collecting promotional leaflets from various stores. Built with performance and reliability in mind.
- Fast and efficient data collection using Playwright
- Robust error handling and automatic retries
- Smart date parsing with multiple format support
- Clean and maintainable codebase
- Comprehensive logging system
- Flexible output formats (JSON/JS)
-
Initialization
- Loads configuration and sets up logging
- Initializes Playwright browser instances
- Prepares data storage structures
-
Data Collection
- Visits store websites using Playwright
- Extracts promotional information
- Parses dates and validates data
- Handles pagination and dynamic content
-
Data Processing
- Normalizes dates to ISO format
- Validates and cleans collected data
- Removes duplicates
- Structures data for export
-
Export
- Saves data in JSON format
- Generates JavaScript module if needed
- Creates backup of results
- Install Python 3.11 or higher
- Install dependencies:
pip install -r requirements.txt
playwright installRun the scraper with default settings:
python main.py- With Verbose Logging
python main.py -v- Custom Output Location
python main.py -o ./data/leaflets.json- Combined Options
python main.py -v -o ./data/leaflets.jsonThe script will:
- Create output directory if it doesn't exist
- Generate JSON file with collected data
- Show progress in console
- Log detailed information if verbose mode is enabled
{
"store_name": "EDEKA",
"title": "Wochenangebote",
"start_date": "2025-03-16",
"end_date": "2025-03-22",
"parsed_time": "2024-03-17 15:30:00"
}const leaflets = [
{
store_name: "EDEKA",
title: "Wochenangebote",
start_date: "2025-03-16",
end_date: "2025-03-22",
parsed_time: "2024-03-17 15:30:00"
}
];main.py: Entry pointscraper.py: Core scraping logicexporters.py: Data export handlersutils.py: Helper functionsmodels.py: Data structuresrequirements.txt: Dependencies
The scraper provides detailed logging for monitoring and debugging:
- Start/end of scraping sessions
- Successful data collection
- Failed requests with retry attempts
- Date parsing results
- Export operations
- Performance metrics
Enable verbose logging with -v flag for maximum detail.
- Playwright Installation
# If playwright install fails
pip install --upgrade pip
pip install playwright
playwright install- Date Parsing Errors
- Check if the date format matches the expected pattern
- Enable verbose logging to see raw date strings
- Dates should be in ISO format (YYYY-MM-DD)
- Connection Issues
- Verify internet connection
- Check if target websites are accessible
- Consider using a VPN if blocked
- Memory Usage
- For large datasets, use the
--outputflag to save to file - Monitor system resources during long runs
- Use
--outputto save results to file for large datasets - Enable verbose logging only when needed
- Consider running during off-peak hours
- Regular updates ensure optimal performance
MIT