擅长:python、mysql、java
<p>如果您不介意外部库,请考虑优秀的<a href="http://docs.python-requests.org/en/latest/index.html" rel="nofollow">^{<cd1>}</a>模块。它用urllib处理这些怪癖。</p>
<p>使用<a href="http://docs.python-requests.org/en/latest/index.html" rel="nofollow">^{<cd1>}</a>的代码是:</p>
<pre><code>import requests
r = requests.get(url, headers={'Accept-encoding': 'gzip'}, timeout=12)
</code></pre>