A Deno-based script that fetches and parses examination results from the KNEC results website. The script sends POST requests with necessary headers and parameters, processes the returned HTML, converts the results table to JSON, and writes the compiled data to a file.
Disclaimer:
This project is not affiliated with, endorsed by, or supported by the Kenya National Examinations Council (KNEC). It is provided for educational and informational purposes only.
- Automated Web Scraping: Fetches result pages for a list of learners.
- HTML Parsing: Uses
node-html-parserto extract relevant data from the HTML. - Table to JSON Conversion: Leverages
tabletojsonto convert HTML tables into JSON objects. - Error Handling & Retries: Implements retries on failed network requests.
- Deno Powered: Utilizes Deno for secure, modern, and efficient TypeScript execution.
- JSON Output: Aggregates all fetched results into a
results.jsonfile.
- Deno installed (version 1.0 or higher).
- An active internet connection to access the KNEC results website.
Clone this repository:
git clone https://github.com/yourusername/knec-results-scraper.git
cd knec-results-scraperThe script uses external modules (node-html-parser and tabletojson) which are imported directly via URLs or from your local environment. Deno handles these dependencies without additional configuration.
-
Configure Learner Indexes
Create or update the
indexes.tsfile with an array of learner objects. For example:export const indexes = [ { INDEXNO: "123456", NAME: "John Doe" }, // Add more learner objects as needed... ];
-
Run the Script
Execute the script with network permissions:
deno run --allow-net fetch_page.ts
The script will iterate over each learner, fetch their exam results, parse the HTML to extract relevant details (such as subject grades, school, mean grade, etc.), and then write the compiled data into a
results.jsonfile.
knec-results-scraper/
├── fetch_page.ts # Main script to fetch and process KNEC results
├── indexes.ts # Module containing learner index data
├── results.json # Output file (generated after running the script)
└── README.md # Project documentation
Contributions, bug reports, and feature requests are welcome! Please feel free to open an issue or submit a pull request if you have improvements or fixes.
This project is licensed under the MIT License.
- node-html-parser
- tabletojson
- The developers of Deno
- KNEC for providing the data source
Happy scraping!