Skip to content

Instantly share code, notes, and snippets.

@richardhsu
Created January 26, 2014 19:15
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 richardhsu/8637724 to your computer and use it in GitHub Desktop.
Save richardhsu/8637724 to your computer and use it in GitHub Desktop.
Request Page from SSA for Names By State with Python 3 and urllib.
#!/usr/bin/env python3
import urllib.request
import urllib.parse
url = 'http://www.ssa.gov/cgi-bin/namesbystate.cgi'
post_data = {
'state': 'IL',
'year': '2012'
}
post_encode = urllib.parse.urlencode(post_data)
post_encode = post_encode.encode('UTF-8')
request = urllib.request.Request(url, post_encode)
response = urllib.request.urlopen(request).read().decode('UTF-8', 'ignore')
# HTML Data now in Response
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment