How revtpark/vahan-scraper works
Purpose and Entry Points
Vahan Scraper extracts vehicle-registration report data from India’s Vahan Dashboard. It offers interchangeable CLI entry points:
• Browser automation producing original XLSX downloads: scripts/scraper.py
• Direct PrimeFaces AJAX/HTTP replay producing parsed CSV: scripts/api.py
Both accept equivalent report-selection and geographic-scope arguments and target the same output directory hierarchy.
Source System Boundary
The system is a client-side data acquisition tool; its external dependency is the live Vahan Dashboard and its server-rendered/PrimeFaces AJAX behavior. Dashboard option lists, report configuration, state/RTO selection, and report data are all obtained at runtime rather than maintained locally.
• scripts/api.py
• scripts/scraper.py
Shared CLI Planning Model
Each command converts axis choices plus temporal and geographic options into a scrape plan. A run may represent:
• an all-states aggregate or a selected state;
• all RTOs, named RTOs, or aggregate state-level data;
• one year or an inclusive year range;
• a list-options discovery mode rather than extraction.
The main control-flow boundary is plan expansion: state/RTO/year combinations become independent report retrieval jobs, enabling partial completion and resume behavior.
• scripts/api.py
• scripts/scraper.py
Browser Retrieval Path
scripts/scraper.py drives Chromium through Playwright, interacting with dashboard controls as a user would. It is the fidelity-oriented path: the dashboard generates and downloads XLSX files directly. Browser startup and per-download interaction make this slower, but it preserves the source export format.
• scripts/scraper.py
• requirements.txt
HTTP/AJAX Retrieval Path
scripts/api.py avoids a browser by replaying the dashboard’s PrimeFaces AJAX protocol over HTTP. It obtains live UI/report state, submits the relevant selection changes and report request, then parses the returned HTML table into CSV. This is the performance-oriented path and depends more directly on undocumented upstream request/response structure.
• scripts/api.py
• requirements.txt
Output, Idempotency, and Failure Boundary
Both paths persist data below the configured output root using a deterministic scope hierarchy: state, RTO, and yaxis__xaxis, with one file per year. Browser jobs write .xlsx; HTTP jobs write .csv. Existing target files are skipped, so completed work is the durable checkpoint for interrupted or repeat runs.
• scripts/scraper.py
• scripts/api.py
Runtime and Dependencies
The project is Python CLI software. The HTTP path requires normal Python HTTP/HTML/CSV-related dependencies; the browser path additionally requires Playwright and a locally installed Chromium runtime. There is no repository-local service, database, or web application layer.
• requirements.txt
• scripts/api.py
• scripts/scraper.py
Main entry points: scraper.py Browser CLI · api.py HTTP CLI · requirements.txt Python dependencies
Components 15
CLI planning
- Report and scope options · Axes, year range, state, RTO, and list-options mode.
- Scrape plan · Expands state/RTO/year scope into independent retrieval jobs.
- Live dashboard state · Report configuration and geographic options are discovered from Vahan.
Browser retrieval
- Browser CLI · Fidelity-oriented XLSX export entry point.
scripts/scraper.py - Playwright Chromium · Automates dashboard controls and downloads.
requirements.txt - Dashboard XLSX export · Original spreadsheet generated by the dashboard.
scripts/scraper.py
HTTP/AJAX retrieval
- HTTP CLI · Performance-oriented CSV extraction entry point.
scripts/api.py - PrimeFaces AJAX replay · Replays selection changes and report requests.
scripts/api.py - Returned HTML table
scripts/api.py - Parsed CSV · HTML report table serialized as CSV.
scripts/api.py
Output and resume
- Output hierarchy · Deterministic state/RTO/yaxis__xaxis paths with one file per year.
- Completed-file checkpoint · Existing target files are skipped for resume behavior.
Other components
- Operator
- Vahan Dashboard · Live server-rendered dashboard and PrimeFaces AJAX endpoint.
- Python dependencies · HTTP/HTML/CSV libraries plus Playwright for browser retrieval.
requirements.txt
Connections 23
- Operator → Browser CLI: runs
- Operator → HTTP CLI: runs
- Browser CLI → Report and scope options: parses
- HTTP CLI → Report and scope options: parses
- Report and scope options → Scrape plan: expands into
- Browser CLI → Live dashboard state: discovers
- HTTP CLI → Live dashboard state: discovers
- Live dashboard state → Vahan Dashboard: loaded from
- Scrape plan → Completed-file checkpoint: checks targets
- Browser CLI → Playwright Chromium: drives
- Playwright Chromium → Vahan Dashboard: interacts with
- Scrape plan → Dashboard XLSX export: retrieves jobs
- Vahan Dashboard → Dashboard XLSX export: generates
- HTTP CLI → PrimeFaces AJAX replay: uses
- Scrape plan → PrimeFaces AJAX replay: submits jobs
- PrimeFaces AJAX replay → Vahan Dashboard: replays requests to
- Vahan Dashboard → Returned HTML table: returns
- Returned HTML table → Parsed CSV: parses to
- Dashboard XLSX export → Output hierarchy: writes
- Parsed CSV → Output hierarchy: writes
- Output hierarchy → Completed-file checkpoint: provides
- Python dependencies → Browser CLI: supports
- Python dependencies → HTTP CLI: supports