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

标签 python html

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

非常感谢!

最佳答案

Requests库允许您在响应进入时对其进行迭代,因此您可以执行如下操作:

import requests
beginning = requests.get('http://example.com/').iter_content(1024).next()

如果您只想要 header ,您始终可以使用 http HEAD 方法:

req = requests.head('http://example.com')

关于python - 是否可以使用 python 获取网页的前几个,比如 1K?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11183371/

相关文章:

html - 为什么 chrome 和 firefox 忽略这个多选择器 CSS 规则?

python - 等到函数在 Python 中完成执行

python - 异常测试失败

javascript - 无法更改 jquery 中的 Top css 值

javascript - 使用 AngularJS 方法绑定(bind)防止重复调用

html - Bootstrap 4 列表组对齐徽章

python - 从嵌套字典获取 pandas 数据框?

python - Google Colaboratory 中的错误 - AttributeError : module 'PIL.Image' has no attribute 'register_decoder'

python - pandas 针对多种条件一次替换多列的内容

html - 在 scss 中使用标记名和父类名称的目标子类,并在其后附加 BEM 命名