You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用requests_html库遇AttributeError:'Future'对象无'html'属性

解决requests_html中AttributeError: 'Future' object has no attribute 'html'的问题

你的代码存在两个明确错误,直接导致了该异常:

  1. 异步调用未使用await
    asession.get()是异步方法,直接调用会返回Future对象而非实际的响应对象,必须通过await关键字等待异步操作完成,才能获取到带有html属性的响应实例。

  2. 属性调用存在笔误
    代码中的r.html.html.arender属于冗余调用,正确写法应为r.html.arender,多写的.html会触发不存在属性的访问错误。

修正后的代码如下:

asession = requests_html.AsyncHTMLSession()
r = await asession.get(link)
await r.html.arender(sleep=2, scrolldown=15)
link = link + "?page=3"
r = await asession.get(link)  # 添加await获取响应对象
await r.html.arender(sleep=8, scrolldown=15)  # 移除多余的.html

内容的提问来源于stack exchange,提问作者Khaled Hamdy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 05:07:12