Last active
August 29, 2015 13:58
-
-
Save mittenchops/10277897 to your computer and use it in GitHub Desktop.
Get state FIPS codes from Gov
This file contains 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 | |
import bs4 as BeautifulSoup | |
def get_states(): | |
page = requests.get("http://www.epa.gov/enviro/html/codes/state.html").content | |
soup = BeautifulSoup.BeautifulSoup(page) | |
def findstates(tr): | |
tds = tr.find_all('td') | |
for td in tds: | |
a = td.find_all("a") | |
if a: | |
return(a[0].text) | |
vals = map(findstates, soup.find_all('tr')) | |
return(filter(None, vals)) | |
states = get_states() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment