Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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