擅长:python、mysql、java
<p>您仍然可以使用<code>urllib</code>。该按钮执行对当前url的发布。使用Firefox的<a href="https://getfirebug.com/" rel="nofollow">Firebug</a>我查看了网络流量,发现它们发送了3个参数:<code>member</code>,<code>top</code>,和{<cd4>}。您可以发送相同的参数:</p>
<pre><code>import urllib
url = 'http://www.ssa.gov/cgi-bin/popularnames.cgi'
post_params = { # member was blank, so I'm excluding it.
'top' : '25',
'year' : year
}
post_args = urllib.urlencode(post_params)
</code></pre>
<p>现在,只需发送url编码的参数:</p>
^{pr2}$
<p>如果您还需要发送邮件头:</p>
<pre><code>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)
</code></pre>
<p>在循环中执行代码:</p>
<pre><code>for year in xrange(1880, 2014):
# The above code...
</code></pre>