2012-02-02 65 views
2

我使用python urllib2.urlopen获取html内容,我得到一个gziped响应。
我可以设置标题,所以我会得到它不拉链?我如何设置一个标题,防止网站发送gzip编码响应

我的代码

response = urlopen(url,None , TIMEOUT) 
html = response.read() # read html 
print html 

为Tichodroma建议我试试这个

request = Request(url) 
request.add_header('Accept-encoding', 'text/plain') 
response = urlopen(request,None , TIMEOUT) 
html = response.read().lower() # read html 
print html 

现在它正在

+0

http://stackoverflow.com/questions/3947120/dose-python-urllib2-will-automaticly-uncompress-gzip-data-from-fetch完全重复 - 网页 – 2012-02-02 11:47:26

+1

没有它不是重复 - 我不想解压缩它我想要得到它不在第一个位置 – yossi 2012-02-02 12:37:25

回答

1

设置Accept头要接受的MIME类型。

Accept: text/plain 

如果你喜欢这个:)

+0

我需要设置request.add_header('接受编码','文本/纯') – yossi 2012-02-02 11:58:30