Skip to content

Instantly share code, notes, and snippets.

@Radcliffe
Last active October 17, 2016 23:29
Show Gist options
  • Save Radcliffe/5e48786e5fb81a961ca02ffca178d98e to your computer and use it in GitHub Desktop.
Save Radcliffe/5e48786e5fb81a961ca02ffca178d98e to your computer and use it in GitHub Desktop.
Get most recent US presidential election predictions from FiveThirtyEight.com
import requests
from bs4 import BeautifulSoup
def main():
url = 'http://projects.fivethirtyeight.com/2016-election-forecast/mobile-bar.html'
r = requests.get(url)
soup = BeautifulSoup(r.text, 'lxml')
return [(p.contents[0], p.contents[1].text)
for p in soup.find_all('p', class_ = 'value-wrap')]
if __name__ == '__main__':
for candidate, probability in main():
print ("%s\t%s" % (candidate, probability))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment