Skip to content

Obtain Dutch election data by scraping the Kiesraad website or parsing EML files

Notifications You must be signed in to change notification settings

DIRKMJK/kiesraad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

The Dutch election council publishes election results in two formats:

  • A website Verkiezingsuitslagen where for each election, each municipality has its own page with local results;
  • Files in Election Markup Language (EML), published at the national government’s data portal.

Background (in Dutch)

Prerequisites

You will need to have Python 3 installed, and the following libraries:

pip3 install pandas xmltodict selenium bs4

Scrape Verkiezingsuitslagen website

This will produce a csv file containing results per municipality.

Example:

from kiesraad import scrape

scrape.scrape('TK20170315')
df = scrape.parse_downloaded_pages('TK20170315')

If you want to extract seats instead of votes:

df = scrape.parse_downloaded_pages('TK20170315', unit='seats')

Parse EML files

This will produce csv files for each municipality, containing results at polling station level. If desired, these can include votes per candidate. Note that you’ll first need to download the EML files from the government’s data portal.

Example:

from pathlib import Path
from kiesraad import parse_eml

source = Path('../data/TK2017')
dfs = parse_eml.parse_eml(source)
target = source / 'csv'
target.mkdir(exist_ok=True)
for name, df in dfs.items():
    path = target / f'{name}.csv'
    df.to_csv(path, index=False)

Caveat

Please check the results; they are not guaranteed to be accurate.

About

Obtain Dutch election data by scraping the Kiesraad website or parsing EML files

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages