Skip to content

Instantly share code, notes, and snippets.

@carloe
Created November 7, 2012 02:55
Show Gist options
  • Save carloe/4029327 to your computer and use it in GitHub Desktop.
Save carloe/4029327 to your computer and use it in GitHub Desktop.
Grabs the current electoral vote counts from huffingtonpost.com
#!/usr/bin/env python
# encoding: utf-8
import re
from urllib import urlopen
html = urlopen("http://elections.huffingtonpost.com/2012/results").read()
result = re.findall("<span class\\=\\\"obama-popular-votes-pct \\\"\\>([0-9]{3})\\<\\/span\\><\\/span\\>\\&nbsp\\;\\&nbsp\\;&nbsp\\;\\<span class\\=\\\"gop\\\"\\><span class\\=\\\"romney-popular-votes-pct \\\"\\>([0-9]{3})\\<\\/span\\>", html, re.S)
print "Obama:\t" + result[0][0]
print "Romney:\t" + result[0][1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment