Skip to content

Instantly share code, notes, and snippets.

@DRMacIver
Created April 14, 2013 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DRMacIver/5382150 to your computer and use it in GitHub Desktop.
Save DRMacIver/5382150 to your computer and use it in GitHub Desktop.
Name Year Seats won Percentage of popular vote
Alliance (NI) 2005 0 0.1
Alliance (NI) 2001 0 0.1
Alliance (NI) 1997 0 0.2
Alliance (NI) 1992 0 0.2
Alliance (NI) 1987 0 0.2
Alliance (NI) 1983 0 0.2
Alliance (NI) 1979 0 0.3
BNP 2005 0 0.7
BNP 2001 0 0.2
BNP 1997 0 0.1
BNP 1992 0 0.1
BNP 1987 0 0.0
BNP 1983 0 0.0
Communist 2005 0 0.0
Communist 2001 0 0.0
Communist 1997 0 0.0
Communist 1992 0 0.0
Communist 1987 0 0.1
Communist 1983 0 0.0
Communist 1979 0 0.1
Community Action Party 2005 0 0.0
Conservative Party 2005 198 30.65
Conservative Party 2001 166 31.7
Conservative Party 1997 165 30.7
Conservative Party 1992 336 41.9
Conservative Party 1987 376 42.2
Conservative Party 1983 397 42.4
Conservative Party 1979 339 43.9
Democratic Unionist 2005 9 0.89
Democratic Unionist 2001 5 0.7
Democratic Unionist 1997 2 0.3
Democratic Unionist 1992 3 0.3
Democratic Unionist 1987 3 0.3
Democratic Unionist 1983 3 0.5
Democratic Unionist 1979 3 0.2
English Democrats Party 2005 0 0.1
Green Party of England and Wales / Green Party 2005 0 1.0
Green Party of England and Wales / Green Party 2001 0 0.6
Green Party of England and Wales / Green Party 1997 0 0.3
Green Party of England and Wales / Green Party 1992 0 0.5
Green Party of England and Wales / Green Party 1987 0 0.3
Green Party of England and Wales / Green Party 1983 0 0.2
Green Party of England and Wales / Green Party 1979 0 0.1
Scottish Green Party 2005 0 0.1
Independents 2005 1 0.5
Independents 2001 0 0.4
Independents 1997 1 0.1
Independents 1992 0 0.1
Independents 1983 0 0.1
Independent Conservative 1997 0 0.0
Independent Conservative 1992 0 0.1
Independent Conservative 1983 0 0.0
Independent Conservative 1979 0 0.0
IKHHC 2005 1 0.1
Independent Labour 1997 0 0.0
Independent Labour 1992 0 0.1
Independent Labour 1983 0 0.1
Independent Labour 1979 1 0.1
Independent Liberal / Independent Liberal Democrat 1997 0 0.0
Independent Liberal / Independent Liberal Democrat 1987 0 0.0
Independent Liberal / Independent Liberal Democrat 1983 0 0.0
Independent Liberal / Independent Liberal Democrat 1979 0 0.0
Independent SDLP 1979 0 0.0
Irish Independence 1979 0 0.1
Labour Party 2005 356 35.24
Labour Party 2001 412 40.7
Labour Party 1997 418 43.2
Labour Party 1992 271 34.4
Labour Party 1987 229 30.8
Labour Party 1983 209 27.6
Labour Party 1979 269 36.9
Legalise Cannabis Alliance 2005 0 0.0
Legalise Cannabis Alliance 2001 0 0.0
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 2005 62 22.06
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 2001 52 18.3
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 1997 46 16.8
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 1992 20 17.8
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 1987 22 22.6
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 1983 23 25.4
Liberal Democrats/SDP-Liberal Alliance/Liberal Party (UK) 1979 11 13.8
Liberal Party (1989) 2005 0 0.1
Liberal Party (1989) 2001 0 0.1
Liberal Party (1989) 1997 0 0.1
Liberal Party (1989) 1992 0 0.2
Monster Raving Loony 2005 0 0.0
Monster Raving Loony 2001 0 0.0
Monster Raving Loony 1997 0 0
Monster Raving Loony 1992 0 0.1
Monster Raving Loony 1987 0 0.0
Monster Raving Loony 1983 0 0.0
National Democrats 1997 0 0.0
National Front 2005 0 0.0
National Front 2001 0 0.0
National Front 1997 0 0.0
National Front 1992 0 0.0
Natural Law Party 1997 0 0.1
Natural Law Party 1992 0 0.2
People's Justice Party 2001 0 0.0
Plaid Cymru 2005 3 0.64
Plaid Cymru 2001 4 0.7
Plaid Cymru 1997 4 0.5
Plaid Cymru 1992 4 0.5
Plaid Cymru 1987 3 0.4
Plaid Cymru 1983 2 0.4
Plaid Cymru 1979 1 0.4
Progressive Unionist Party 2001 0 0.0
Progressive Unionist Party 1997 0 0.1
ProLife Alliance 2001 0 0.0
ProLife Alliance 1997 0 0.1
Protestant Unionist 1987 0 0.0
RESPECT The Unity Coalition 2005 1 0.3
Scottish Labour Party 1979 0 0.1
Scottish Militant Labour 1992 0 0.1
Scottish National Party 2005 6 1.57
Scottish National Party 2001 5 1.8
Scottish National Party 1997 6 2.0
Scottish National Party 1992 3 1.9
Scottish National Party 1987 3 1.3
Scottish National Party 1983 1 1.1
Scottish National Party 1979 2 1.6
Scottish Socialist Party 2005 0 0.2
Scottish Socialist Party 2001 0 0.3
Scottish Socialist Party 1997 0 0.0
Sinn Féin / Independent Republican 2005 5 0.64
Sinn Féin / Independent Republican 2001 4 0.7
Sinn Féin / Independent Republican 1997 2 0.4
Sinn Féin / Independent Republican 1992 0 0.2
Sinn Féin / Independent Republican 1987 0.3 1
Sinn Féin / Independent Republican 1983 0.3 1
Sinn Féin / Independent Republican 1979 0.1 0
SDLP 2005 3 0.5
SDLP 2001 3 0.6
SDLP 1997 3 0.6
SDLP 1992 4 0.5
SDLP 1987 3 0.5
SDLP 1983 1 0.4
SDLP 1979 1 0.4
Social Democratic Party 1992 0 0.1
Socialist Labour 2005 0 0.1
Socialist Labour 2001 0 0.2
Socialist Labour 1997 0 0.2
Socialist Alliance 2005 0 0.0
Socialist Alliance 2001 0 0.0
Socialist Alliance 1997 0 0.0
Ulster Popular Unionist / Independent Ulster Unionist 1992 1 0.1
Ulster Popular Unionist / Independent Ulster Unionist 1987 1 0.1
Ulster Popular Unionist / Independent Ulster Unionist 1983 1 0.1
Ulster Popular Unionist / Independent Ulster Unionist 1979 1 0.1
Ulster Unionist 2005 1 0.5
Ulster Unionist 2001 6 0.8
Ulster Unionist 1997 10 0.8
Ulster Unionist 1992 9 0.8
Ulster Unionist 1987 9 0.8
Ulster Unionist 1983 1 0.8
Ulster Unionist 1979 5 0.8
Unionist Party 1979 0 0.0
United Ulster Unionist 1979 1 0.1
UK Independence Party 2005 0 2.3
UK Independence Party 2001 0 1.5
UK Independence Party 1997 0 0.3
UK Unionist / Real Unionist 2001 0 0.1
UK Unionist / Real Unionist 1997 1 0.1
UK Unionist / Real Unionist 1987 0 0.1
Veritas 2005 0 0.1
Workers' Party 2005 0 0.0
Workers' Party 2001 0 0.0
Workers' Party 1997 0 0.0
Workers' Party 1992 0 0.1
Workers' Party 1987 0 0.1
Workers' Party 1983 0 0.0
Workers' Party 1979 0 0.1
Alliance (NI) 0 0 0.2
Alliance (NI) 0 0 0.1
BNP 1966 0 0.0
Communist 0 0 0.1
Communist 0 0 0.1
Communist 1970 0 0.1
Communist 1966 0 0.2
Communist 1964 0 0.2
Communist 1959 0 0.1
Communist 1955 0 0.1
Conservative Party 0 277 35.8
Conservative Party 0 297 37.9
Conservative Party 1970 330 46.4
Conservative Party 1966 253 41.9
Conservative Party 1964 304 43.4
Conservative Party 1959 365 49.4
Conservative Party 1955 345 49.7
Democratic Labour 0 0 0.1
Democratic Labour 0 1 0.1
Democratic Party 1970 0 0.1
Democratic Unionist Party 0 1 0.3
Democratic Unionist Party 0 1 0.2
Labour Party 0 313 39.2
Labour Party 0 301 37.2
Labour Party 1970 287 43.1
Labour Party 1966 364 48.0
Labour Party 1964 317 44.1
Labour Party 1959 258 43.4
Labour Party 1955 277 46.4
Labour Party (Ireland) 1955 0 0.1
Labour Party(NI) 0 0 0.0
Labour Party(NI) 0 0 0.0
Liberal Party 0 13 18.3
Liberal Party 0 14 19.3
Liberal Party 1970 6 7.5
Liberal Party 1966 12 8.5
Liberal Party 1964 9 11.2
Liberal Party 1959 6 5.9
Liberal Party 1955 6 2.7
National Front 0 0 0.4
National Front 0 0 0.2
National Front 1970 0 0.1
Plaid Cymru 0 3 0.6
Plaid Cymru 0 2 0.5
Plaid Cymru 1970 0 0.6
Plaid Cymru 1966 0 0.2
Plaid Cymru 1964 0 0.2
Plaid Cymru 1959 0 0.3
Plaid Cymru 1955 0 0.2
Independents 0 0 0.0
Independents 0 0 0.1
Independents 1970 0 0.1
Independents 1966 0 0.1
Independents 1964 0 0.1
Independents 1959 0 0.0
Independents 1955 0 0.2
Independent Conservative 0 0 0.0
Independent Conservative 0 0 0.0
Independent Conservative 1970 0 0.1
Independent Conservative 1966 0 0.0
Independent Conservative 1964 0 0.0
Independent Conservative 1959 1 0.1
Independent Labour 0 0 0.2
Independent Labour 0 1 0.1
Independent Labour 1970 1 0.1
Independent Labour 1966 0 0.0
Independent Labour 1955 0 0.0
Independent Liberal 0 0 0.0
Independent Liberal 0 0 0.2
Independent Liberal 1970 0 0.0
Independent Liberal 1966 0 0.0
Independent Liberal 1964 0 0.1
Independent Liberal 1959 0 0.0
Independent Socialist 0 0 0.0
Independent Republican / Sinn Féin 0 1 0.2
Independent Republican / Sinn Féin 0 0 0.0
Independent Republican / Sinn Féin 1966 0 0.2
Independent Republican / Sinn Féin 1964 0 0.4
Independent Republican / Sinn Féin 1959 0 0.2
Independent Republican / Sinn Féin 1955 2 0.6
National Democratic 1970 0 0.1
National Democratic 1966 0 0.0
National Democratic 1964 0 0.0
National Democrats (NI) 1970 0 0.1
Nationalist (NI) 1966 0 0.1
NI Independent Labour 1959 0 0.1
Protestant Unionist Party 1970 1 0.1
Republican Clubs 0 0 0.1
Republican Clubs 0 0 0.0
Republican Labour 1970 1 0.1
Republican Labour 1966 1 0.1
Republican Labour 1964 0 0.1
Scottish National Party 0 11 2.9
Scottish National Party 0 7 2.0
Scottish National Party 1970 1 1.1
Scottish National Party 1966 0 0.5
Scottish National Party 1964 0 0.2
Scottish National Party 1959 0 0.1
Scottish National Party 1955 0 0.0
SDLP 0 1 0.6
SDLP 0 1 0.5
Ulster Unionist Party 0 6 0.9
Ulster Unionist Party 0 7 0.8
Ulster Unionist Party 1970 Before 1974, The UUP MPs sat in parliament as part of the Conservative Party
Unionist (NI) / Pro-Assembly Unionist 0 0 0.1
Unionist (NI) / Pro-Assembly Unionist 0 0 0.3
Unity 0 0 0.0
Unity 1970 2 0.4
Vanguard Progressive Unionist Party 0 3 0.3
Vanguard Progressive Unionist Party 0 3 0.2
Agricultural Party 1945 0 0.0
Agricultural Party 1935 0 0.0
Agricultural Party 1931 0 0.0
Anti-Partition 1951 0 0.0
Anti-Partition 1950 0 0.0
Common Wealth 1945 1 0.5
Commonwealth Labour 1945 0 0.1
Communist 1951 0 0.1
Communist 1950 0 0.3
Communist 1945 2 0.4
Communist 1935 1 0.1
Communist 1931 0 0.3
Communist 1929 0 0.2
Conservative Party 1951 302 44.3
Conservative Party 1950 282 40.0
Conservative Party 1945 197 36.2
Conservative Party 1935 387 47.8
Conservative Party 1931 470 55.50
Conservative Party 1929 260 38.1
Independent 1951 0 0.1
Independent 1950 0 0.2
Independent 1945 8 0.6
Independent 1935 2 0.1
Independent 1931 1 0.0
Independent 1929 4 0.4
Independent Conservative 1951 0 0.0
Independent Conservative 1950 0 0.1
Independent Conservative 1945 2 0.2
Independent Conservative 1935 0 0.1
Independent Labour 1950 0 0.1
Independent Labour 1945 2 0.3
Independent Labour 1935 0 0.1
Independent Labour 1931 0 0.1
Independent Labour 1929 1 0.1
Independent Labour Party 1951 0 0.0
Independent Labour Party 1950 0 0.0
Independent Labour Party 1945 3 0.2
Independent Labour Party 1935 4 0.7
Independent Liberal 1950 1 0.1
Independent Liberal 1945 2 0.1
Independent Liberal 1935 0 0.0
Independent Liberal 1931 0 0.0
Independent Liberal 1929 0 0.1
Independent Nationalist 1951 2 0.3
Independent Nationalist 1945 0 0.0
Independent Nationalist 1931 0 0.0
Independent Progressive 1945 1 0.1
Independent Progressive 1935 0 0.0
Irish Nationalist 1950 2 0.2
Irish Nationalist 1945 2 0.4
Irish Nationalist 1935 2 0.2
Irish Nationalist 1931 2 0.4
Irish Nationalist 1929 3 0.1
Labour Party 1951 295 48.8
Labour Party 1950 315 46.1
Labour Party 1945 393 47.71
Labour Party 1935 154 38.0
Labour Party 1931 52 30.8
Labour Party 1929 287 37.1
Labour Party (Ireland) 1951 1 0.1
Labour Party (Ireland) 1950 0 0.2
Liberal Party 1951 6 2.5
Liberal Party 1950 9 9.1
Liberal Party 1945 12 9.04
Liberal Party 1935 21 6.7
Liberal Party 1931 32 6.5
Liberal Party 1929 59 23.6
Liverpool Protestant 1945 0 0.0
Liverpool Protestant 1935 0 0.0
Liverpool Protestant 1931 0 0.0
National 1945 2 0.5
National 1935 1 0.3
National 1931 4 0.5
National Independent 1950 0 0.0
National Independent 1945 2 0.3
National Independent 1935 2 0.2
National Independent 1931 2 0.2
National Labour 1950 0 0.0
National Liberal 1951 19 3.7
National Liberal 1950 16 3.4
National Liberal 1945 11 2.9
National Liberal 1935 33 3.7
National Liberal 1931 35 3.7
National Party of Scotland 1931 0 0.1
National Party of Scotland 1929 0 0.0
New Party 1931 0 0.2
Plaid Cymru 1951 0 0.0
Plaid Cymru 1950 0 0.1
Plaid Cymru 1945 0 0.0
Plaid Cymru 1935 0 0.0
Plaid Cymru 1931 0 0.0
Plaid Cymru 1929 0 0.0
Scottish National Party 1951 0 0.0
Scottish National Party 1950 0 0.0
Scottish National Party 1945 0 0.1
Scottish National Party 1935 0 0.2
Scottish Prohibition 1931 0 0.1
Scottish Prohibition 1929 1 0.1
Sinn Féin 1951 0 0.1
Sinn Féin 1950 0 0.1
Agricultural Party 1922 0 0.2
Belfast Labour Party 1924 0 0.2
Communist 1924 1 0.2
Communist 1923 0 0.2
Communist 1922 1 0.2
Constitutionalist 1924 7 1.2
Constitutionalist 1923 0 0.1
Constitutionalist 1922 1 0.1
Conservative 1924 412 46.8
Conservative 1923 258 38.0
Conservative 1922 344 38.5
Independent 1924 2 0.2
Independent 1923 2 0.3
Independent 1922 3 0.8
Independent Conservative 1924 0 0.0
Independent Conservative 1923 0 0.1
Independent Conservative 1922 3 0.9
Independent Labour 1924 0 0.0
Independent Labour 1923 0 0.2
Independent Labour 1922 1 0.1
Independent Liberal 1923 1 0.1
Independent Liberal 1922 1 0.1
Independent Nationalist 1922 0 0.1
Irish Nationalist 1924 1 0.0
Irish Nationalist 1923 3 0.4
Irish Nationalist 1922 3 0.4
Labour Party 1924 151 33.3
Labour Party 1923 191 30.7
Labour Party 1922 142 29.7
Labour Party (Northern Ireland) 1924 0 0.1
Liberal Party 1924 40 17.8
Liberal Party 1923 158 29.7
Liberal Party 1922 62 18.9
National Liberal 1922 53 9.9
Scottish Prohibition 1924 1 0.1
Scottish Prohibition 1923 1 0.1
Scottish Prohibition 1922 1 0.1
Sinn Féin 1924 0 0.2
require "open-uri"
require "rubygems"
require "nokogiri"
html = Nokogiri(open("http://en.wikipedia.org/wiki/United_Kingdom_general_elections_overview").read)
tables = html.css("table")[1..-1]
Datum = Struct.new(:name, :year, :seats, :popular)
def header(table)
table.css("th").map{|x| x.text}.join("|")
end
def parse_table(table)
unless block_given?
results = []
parse_table{|d| results << d}
return results
end
rows = table.css("tr")
years = rows[0].css("td")[1..-1].map(&:text).map(&:to_i)
data_rows = rows[2..-1]
data_rows.each do |row|
columns = row.css("td")
name = columns[0].text
data = columns[1..-1].map{|x| x.text.strip}.each_slice(2).to_a
data.each_with_index do |(popular, seats), i|
if popular != "-" && seats != "-"
yield Datum.new(name, years[i], seats, popular)
end
end
end
end
puts "Name\tYear\tSeats won\tPercentage of popular vote"
tables.each do |t|
parse_table(t){ |d| puts [d.name, d.year, d.seats,d.popular].join("\t") }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment