Getting HEAD content with Python Requests

后端 未结 3 1115
终归单人心
终归单人心 2020-12-03 04:51

I\'m trying to parse the result of a HEAD request done using the Python Requests library, but can\'t seem to access the response content.

According to the docs, I sh

相关标签:
3条回答
  • 2020-12-03 05:36

    A HEAD doesn't have any content! Try response.headers - that's probably where the action is. An HTTP HEAD request doesn't get the <head> element of the HTML response you would get from a GET request. I think that's your mistake.

    0 讨论(0)
  • 2020-12-03 05:47

    By definition, the responses to HEAD requests do not contain a message-body.

    Send a GET request if you want to, well, get a response body. Send a HEAD request iff you are only interested in the response status code and headers.

    HTTP transfers arbitrary content; the HTTP term header is completely unrelated to an HTML <head>. However, HTTP can be advised to download only a part of the document. If you know the length of the HTML <head> code (or an upper boundary therefor), you can include an HTTP Range header in your request that advises the remote server to only return a certain number of bytes. If the remote server supports HTTP ranges, it will then serve the reduced answer.

    0 讨论(0)
  • 2020-12-03 05:53

    HEAD responses have no body. They only return HTTP headers, the same you would get using a GET request.

    0 讨论(0)
提交回复
热议问题