是否可以使用python获取网页的前几个,比如1K?
非常感谢!
答案 0 :(得分:6)
Requests库允许您在响应时迭代响应,以便您可以执行以下操作:
import requests
beginning = requests.get('http://example.com/').iter_content(1024).next()
如果您只想要标题,可以随时使用http HEAD方法:
req = requests.head('http://example.com')
答案 1 :(得分:0)
以下是使用内置的Python 3 urllib.request的示例。
import urllib.request
url = urllib.request.openurl("http://example.com").read(1024)
答案 2 :(得分:0)
不确定
>>> len(urllib2.urlopen('http://google.com').read(1024))
1024