Last active
October 17, 2016 23:29
-
-
Save Radcliffe/5e48786e5fb81a961ca02ffca178d98e to your computer and use it in GitHub Desktop.
Get most recent US presidential election predictions from FiveThirtyEight.com
This file contains hidden or 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
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