How to Extract Http Response Body from a Python Requests Call?

I'm using the Python requests library. I'm trying to figure out how to extract the actual HTML body from a response. The code looks a bit like this:

r = requests.get(...)
print r.content

This should indeed print lots of content, but instead prints nothing.

Any suggestions? Maybe I've misunderstood how requests.get() works?

3 Answers

Your code is correct. I tested:

r = requests.get("")
print(r.content)

And it returned plenty of content. Check the url, try "". Cheers!

1

You can try this method:

import requests

response = requests.get("")
response.raise_for_status()

data = response.json()
print(data)

import requests

site_request = requests.get("")

site_response = str(site_request.content)

print(site_response)

You can do it either way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest