<p>我怀疑发生的是服务器在发送压缩数据时没有告诉您它正在这样做。Python的标准HTTP库不能处理压缩格式。<br/>我建议使用httplib2,它可以处理压缩格式(通常比urllib好得多)。</p>
<pre><code>import httplib2
folder = httplib2.Http('.cache')
response, content = folder.request("http://www.boursorama.com/includes/cours/last_transactions.phtml?symbole=1xEURUS")
</code></pre>
<p/><p><code>print(response)</code>显示服务器的响应:<br/>
{'status':'200','content length':'7787','x-sid':'26,E','content language':'fr','set cookie':'PHPSESSIONID=ed45f761542752317963ab4762ec604f;path=/;domain=.www.boursorama.com','expires':'Thu,1981年11月19日08:52:00 GMT','vary':'Accept Encoding,User Agent','server':'nginx','connection':'keep alive',<b>'-content encoding':'gzip'</b>,'pragma':'no cache','cache control':'no store,no cache,must revalidate,post check=0,pre check=0','date':'Tue,2011年8月23日10:26:46 GMT','content type':'text/html;charset=ISO-8859-1','content location':'http://www.boursorama.com/includes/cours/last懔transactions.phtml?符号=1xEURUS'}
</p><p>虽然这不能确认它是压缩的(毕竟,我们现在告诉服务器我们可以处理压缩),但它确实给理论增加了一些分量。</p>
<p>你猜,真正的内容存在于<code>content</code>。简单地看一下,就可以看出它在工作(我只需要粘贴一点):<br/>
<code>b'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"\n\t"http://</code></p>
<p><strong>Edit<strong>:是的,这确实创建了一个名为.cache的文件夹;我发现,当涉及到httplib2时,使用文件夹总是更好的,并且您可以在以后删除该文件夹。</p>