小编use*_*924的帖子

urllib2 python(Transfer-Encoding:chunked)

我使用以下python代码下载html页面:

response = urllib2.urlopen(current_URL)
msg = response.read()  
print msg
Run Code Online (Sandbox Code Playgroud)

对于像这样的页面,它会打开网址而不会出现错误,但只打印部分html页面!

在以下行中,您可以找到html页面的http标头.我认为这个问题是由于"Transfer-Encoding:chunked"造成的.

似乎urllib2只返回第一个块!我在阅读其余的块时遇到了困难.我怎么能读剩下的块?

Server: nginx/1.0.5
Date: Wed, 27 Feb 2013 14:41:28 GMT
Content-Type: text/html;charset=UTF-8
Transfer-Encoding: chunked
Connection: close
Set-Cookie: route=c65b16937621878dd49065d7d58047b2; Path=/
Set-Cookie: JSESSIONID=EE18E813EE464664EA64086D5AE9A290.tpdjo13v_3; Path=/
Pragma: No-cache
Cache-Control: no-cache,no-store,max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Vary: Accept-Encoding
Content-Language: fr
Run Code Online (Sandbox Code Playgroud)

python urllib2 chunked transfer-encoding

5
推荐指数
1
解决办法
2323
查看次数

标签 统计

chunked ×1

python ×1

transfer-encoding ×1

urllib2 ×1