有没有可能使用python获取网页的前几个内容,比如1K?
非常感谢!
发布于 2012-06-25 12:23:01
Requests库允许您在收到响应时对其进行迭代,因此您可以执行以下操作:
import requests
beginning = requests.get('http://example.com/').iter_content(1024).next()如果你只想要头文件,你可以使用http HEAD方法:
req = requests.head('http://example.com')发布于 2012-06-25 13:45:55
下面是一个使用Python3的urllib.request的例子,它是内置的。
import urllib.request
url = urllib.request.openurl("http://example.com").read(1024)发布于 2012-06-25 14:35:39
当然:
>>> len(urllib2.urlopen('http://google.com').read(1024))
1024https://stackoverflow.com/questions/11183371
复制相似问题