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