Logo Lanfrica

bgathecha/dnld_knbs_economic_reports

Domain:

socioeconomic

Record type:

software
Creator:
bga
Host:
A python-based web scraper for automatically downloading Economic Survey PDF reports from the Kenya National Bureau of Statistics(KNBS) website # πŸ“Š KNBS Economic Survey Scraper A Python-based web scraper for automatically downloading Economic Survey PDF reports from the Kenya National Bureau of Statistics (KNBS) website. --- ## πŸš€ Features - Scrapes Economic Survey reports from 1960 to present - Recursively handles pagination - Downloads only new files (skips existing) - Parameterized for flexible use - Easy to schedule for yearly automation --- ## πŸ“ Project Structure ``` knbs_scraper/ β”œβ”€β”€ scraper.py # Main scraping logic β”œβ”€β”€ test_scraper.py # Unit tests β”œβ”€β”€ requirements.txt # Dependencies └── README.md ``` --- ## πŸ› οΈ Installation ```bash git clone github.com cd dnld_knbs_economic_reports python -m venv .venv source .venv/bin/activate # or .venv\Scripts\activate on Windows pip install -r requirements.txt ``` --- ## βš™οΈ Usage ```bash python scraper.py --url "knbs.or.ke" --output-dir "datafiles/" ``` **Arguments:** - `--url`: Start URL to scrape (required) - `--output-dir`: Folder to store files (default: `datafiles/`) --- ## πŸ§ͺ Running Tests ```bash python -m unittest test_scraper.py ``` --- ## βœ… Ethical Considerations - Abides by robots.txt - Does not overload the server (add sleep/delay if needed) - Intended for educational and research use - Always review the site's Terms of Service --- ## πŸ“… Automation Tip To run this scraper annually, use: - **Linux/macOS**: `cron` - **Windows**: Task Scheduler - **GitHub Actions**: for serverless automation --- ## πŸ“Œ TODO - Add support for date filtering - Enable logging instead of prints - Add scraping rate limiter --- ## πŸ‘¨β€πŸ’» Author - **Benson Muchoki** – GitHub Repo