python - 对于 python,<class 'requests.models.Response' > 是什么意思

标签 python class python-requests

我尝试使用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/

相关文章:

Python nxt mindstorms 连接问题

python - 防止变量替换发生在构建中

python - 类方法和类方法中定义的变量

java - 返回接口(interface)而不是类<Interface>

Python 从网站上抓取 PDF 文件 为什么它们都已损坏且大小相同?

networking - 一台机器可以从多个不同的IP地址发出请求吗?

python - 将纬度、经度和高度转换为平面 3D 空间中的点

python - 为什么 'kd_tree' 比 'brute' 花费更多时间?

java - 我们是否在 UML 类图中的两个类中应用相同的操作?

python - 页面请求未完全加载