Advertisement
dc5553

Web Scrape Baby Names by Year Social Security Agency

Jan 8th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. import urllib2
  2. import urllib
  3. from time import sleep
  4.  
  5. myurl = 'https://www.ssa.gov/cgi-bin/popularnames.cgi'
  6.  
  7. for page in range(1880,2016):
  8.     mydata = urllib.urlencode({'year': page, 'top':'1000'})
  9.     myfilename = "baby{}.html".format(page)
  10.     wf = open(myfilename,"w")
  11.     req = urllib2.Request(myurl, mydata)
  12.     print req.get_full_url(), req.get_data()
  13.     response = urllib2.urlopen(req)
  14.     text = response.read()
  15.     wf.write(text)
  16.     wf.close()
  17.     sleep(1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement