我使用以下 python 代码来下载 html 页面:
response = urllib2.urlopen(current_URL)
msg = response.read()
print msg
对于诸如以下的页面this one,它打开 url 时没有错误,但随后仅打印 html 页面的一部分!
在以下几行中,您可以找到 html 页面的 http 标头。我认为问题是由于“传输编码:分块”造成的。
看来 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
我发现如果指定了 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'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)