如何从Python请求调用中提取HTTP响应正文? [英] How to extract HTTP response body from a Python requests call?
本文介绍了如何从Python请求调用中提取HTTP响应正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Python请求库.我试图弄清楚如何从响应中提取实际的HTML正文.代码看起来像这样:
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.
有什么建议吗?也许我误解了requests.get()的工作原理?
Any suggestions? Maybe I've misunderstood how requests.get() works?
推荐答案
您的代码正确.我测试了:
Your code is correct. I tested:
r = requests.get("http://www.google.com")
print(r.content)
它返回了很多内容.检查网址,尝试" http://www.google.com ".干杯!
And it returned plenty of content. Check the url, try "http://www.google.com". Cheers!
这篇关于如何从Python请求调用中提取HTTP响应正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文