Skip to content

Instantly share code, notes, and snippets.

@gldomingo
Last active August 20, 2016 23:50
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 gldomingo/ec1c9f3b6d8f229792594f958d940b50 to your computer and use it in GitHub Desktop.
Save gldomingo/ec1c9f3b6d8f229792594f958d940b50 to your computer and use it in GitHub Desktop.
web_scraping
### GETS LIST AND SEPARATES PRESIDENTS FROM VPs
p_td = p.find_all('td')
pres = []
vp = []
for tag in p_td:
try:
int(tag.get_text()[0])
pres.append(tag.get_text())
except (ValueError):
vp.append(tag.get_text())
### RETRIEVES LIST OF P AND VP BY PARTY
party = p2.find_all('div',{'class':"col-xs-3"})
### RETURNS LIST OF PRESIDENTS AND VPs BY PARTY
for i in range(len(party)):
if i == 0:
rep = party[i].get_text().split('\n')
elif i == 1:
dem = party[i].get_text().split('\n')
elif i == 2:
other = party[i].get_text().split('\n')
else:
etc = party[i].get_text().split('\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment