gpt4 book ai didi

Python请求: Anyway to download just the body of a get response?

转载 作者:太空宇宙 更新时间:2023-11-03 17:30:02 24 4
gpt4 key购买 nike

所以我首先使用requests.head()来下载 header 。我做了一些验证(检查状态代码,检查内容类型)如果这是好的我下载正文。不过,我使用 requests.get() 来实现这一点,但是使用 .get() 不仅会下载正文,还会下载我刚刚下载的 header 。所以我不需要下载 header 两次,无论如何,如果 header 看起来不错,我可以下载获取响应的正文?

最佳答案

不,没有办法。 HTTP 有 HEAD 请求,它只获取 header,但没有只获取 body 的请求。

除非需要,否则不要太担心效率;无论如何,标题通常不会太大。如果主体很小,则首先使用 requests.get() ,否则使用 requests.head() ,然后使用 requests.get() 如果需要的话。

关于Python请求: Anyway to download just the body of a get response?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32003889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com