This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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"] |