You can use urllib . The button performs a POST for the current URL. Using Firefox Firebug I looked at network traffic and found that it sends 3 parameters: member , top and year . You can send the same arguments:
import urllib url = 'http://www.ssa.gov/cgi-bin/popularnames.cgi' post_params = {
Now just send url-encoded arguments:
urllib.urlopen(url, post_args)
If you need to also send headers:
headers = { 'Accept' : 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'Accept-Language' : 'en-US,en;q=0.5', 'Connection' : 'keep-alive', 'Host' : 'www.ssa.gov', 'Referer' : 'http://www.ssa.gov/cgi-bin/popularnames.cgi', 'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0' } # With POST data: urllib.urlopen(url, post_args, headers)
Run the code in a loop:
for year in xrange(1880, 2014):
source share