An API scraped together to make it easy to see and work with MP and MLA data submitted at the time of elections.
MPs (Members of Parliament): 2004, 2009, 2014, 2019, 2024
Base URL: https://nish.space/my_neta/
Endpoint : '/mps'
Endpoint : '/mlas'
The scraper has been updated to work with the current myneta.info website structure. It handles both the old format (pre-2019) and new format (2019+) automatically.
# Scrape both MPs and MLAs
rake db:scrape# Scrape all available MP years (2004, 2009, 2014, 2019, 2024)
rake db:scrape_mps
# Scrape specific years
rake db:scrape_mps[2024]
rake db:scrape_mps[2019,2024]
rake db:scrape_mps[2004,2009,2014]To re-scrape a year (deletes existing data first):
# Re-scrape 2024 (with confirmation prompt)
rake db:rescrape_mps[2024]
# Re-scrape multiple years
rake db:rescrape_mps[2019,2024]To add data for new election years (e.g., 2029):
Edit my_neta.rb and add the new year to the YEARS array:
YEARS = %w(2004 2009 2014 2019 2024 2029)Edit lib/neta_scraper.rb and add the known URL for the new year to KNOWN_MP_URLS:
KNOWN_MP_URLS = {
'2024' => 'https://myneta.info/LokSabha2024/index.php?action=show_winners&sort=default',
'2019' => 'https://myneta.info/LokSabha2019/index.php?action=show_winners&sort=default',
'2014' => 'https://myneta.info/ls2014/index.php?action=show_winners&sort=default',
'2009' => 'https://myneta.info/ls2009/index.php?action=show_winners&sort=default',
'2004' => 'https://myneta.info/LokSabha2004/index.php?action=show_winners&sort=default',
'2029' => 'https://myneta.info/LokSabha2029/index.php?action=show_winners&sort=default' # Add here
}.freeze# Scrape the new year
rake db:scrape_mps[2029]# Check count for the new year
curl https://nish.space/my_neta/mps/2029
# Or with the API running locally
curl http://localhost:9292/mps/2029- State Extraction: For 2019+, the scraper fetches individual candidate pages to extract state information. This is cached to avoid repeated requests.
- New Structure: The 2024+ site uses 8 columns (vs 16 in older years). The scraper automatically detects and handles both formats.
- Rate Limiting: The scraper adds small delays between candidate page fetches to be respectful of the server.
- Fallback: If state extraction fails, a constituency-to-state mapping is used as a fallback.