加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – AttributeError:’Response’对象没有属性’text’

发布时间:2020-12-20 11:34:32 所属栏目:Python 来源:网络整理
导读:page = requests.get(url)tree = html.fromstring(page.text) 在第2行,我得到: AttributeError: 'Response' object has no attribute 'text' 我已导入请求和已安装的请求.如何调试此错误?任何人都可以告诉命令安装最新的请求模块? 解决方法 您正在使用古
page = requests.get(url)
tree = html.fromstring(page.text)

在第2行,我得到:

AttributeError: 'Response' object has no attribute 'text'

我已导入请求和已安装的请求.如何调试此错误?任何人都可以告诉命令安装最新的请求模块?

解决方法

您正在使用古老版本的请求,很可能是因为它安装了 Ubuntu Precise Pengolin (12.04LTS).

您要么必须参考version specific documentation,要么使用更新版本.自0.x版本日以来,请求发生了巨大变化.

对于旧版本,如果设置response.encoding,则response.content将包含已解码的Unicode值.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读