是否有可能使用python获取网页的前几个,比如1K?

Les*_*e G 1 python webpage

是否有可能使用python获取网页的前几个,比如1K?

非常感谢你!

Tre*_*vor 6

请求库用于遍历的响应,因为它进来,所以你可以做这样的事情:

import requests
beginning = requests.get('http://example.com/').iter_content(1024).next()
Run Code Online (Sandbox Code Playgroud)

如果您只想要标题,可以随时使用http HEAD方法:

req = requests.head('http://example.com')
Run Code Online (Sandbox Code Playgroud)