我尝试使用python中的Requests库进行爬取,我首先导入requests模块,然后我使用get函数调用网站获取名为r的响应,但我不明白为什么r的类型是class,你能请告诉我原因,非常感谢。
我也想查请求头,查了一些文档,说可以用r.request.headers,这里的请求是什么意思,是方法吗?
>>> import requests
>>> r=requests.get("http://www.baidu.com")
>>> type(r)
<class 'requests.models.Response'>
最佳答案
您收到了 Response
发出请求后的对象。要从响应对象获取数据,您需要访问您想要的属性,例如r.status_code
, r.text
, 等等。
见 this documentation更多细节。
关于python - 对于 python,<class 'requests.models.Response' > 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47193745/