Skip to content

Instantly share code, notes, and snippets.

@ijmbarr
ijmbarr / GEscraping
Created January 17, 2015 13:50
Functions for scrapping election results from http://www.politicsresources.net/area/uk/edates.htm.
#Functions for scrapping UK general election results from http://www.politicsresources.net/area/uk/edates.htm.
#point "processAYear" at the index page for a year (e.g. "http://www.politicsresources.net/area/uk/ge50/")
#The function returns a list of dictionary objects representing the results for each constituency.
from bs4 import BeautifulSoup
import requests
def processAYear(url):
page = BeautifulSoup(requests.get(url).text)
tables = [x.get("href") for x in page.findAll("a") if x.get("href")[0] == "i"]