【问题标题】:urllib2 python (Transfer-Encoding: chunked)urllib2 python(传输编码:分块)
【发布时间】:2013-02-13 11:13:18
【问题描述】:

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

response = urllib2.urlopen(current_URL)
msg = response.read()  
print msg

对于像this one这样的页面,它打开url没有错误,但只打印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

【问题讨论】:

    标签: python urllib2 chunked transfer-encoding


    【解决方案1】:

    我发现如果我指定了 Accept-Language 标头,则服务器不会断开 TCP 连接,否则它会。

    curl -H "Accept-Language:uk,en-US;q=0.8,en;q=0.6,ru;q=0.4" -v 'http://www.legifrance.gouv.fr/affichJuriJudi.do?oldAction=rechJuriJudi&idTexte=JURITEXT000024053954&fastReqId=660326373&fastPos=1'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      • 2012-11-02
      • 2012-02-18
      • 2012-01-26
      • 2014-11-08
      • 2011-03-14
      • 1970-01-01
      相关资源
      最近更新 更多