Python中文
首页
教程
问答
标签
搜索
登录
注册
AttributeError:“Response”对象没有属性“txt”Python Web抓取
回答此问题可获得
20
贡献值,回答如果被采纳可获得
50
分。
<p>我正在开发一个新的项目,以摆脱我能做的最基本的事情,我决定研究网页抓取。 我的想法是使用<a href="https://www.steamstatus.io/" rel="nofollow noreferrer">SteamStatus</a>检查Steam的当前状态,并让我的脚本打印它。对于第一个,我使用了蒸汽商店的状态,并编写了以下代码:</p> <pre><code>import requests import bs4 res = requests.get('https://www.steamstatus.io/') res.raise_for_status SteamStatus = bs4.BeautifulSoup(res.txt, 'html.parser') type(SteamStatus) storeStatus = SteamStatus.select('#statustables > div.statustable.left > div > div:nth-child(1) > div.statusrow_status.store-status') print(str(storeStatus)) </code></pre> <p>这样,我得到了以下错误:</p> <pre><code>Traceback (most recent call last): File "C:/Users/a864/PycharmProjects/automation/steam status/webpage.py", line 8, in <module> SteamStatus = bs4.BeautifulSoup(res.txt, 'html.parser') AttributeError: 'Response' object has no attribute 'txt' </code></pre> <p>根据我的搜索和发现,这可能是请求模块的过时版本的问题,但我已经确定我有最新版本(2.24.0)</p>
0 条评论
分类:
Python问答
请先
登录
后评论
默认排序
时间排序
1 个回答
匿名
1天前
擅长:python、mysql、java
<p>正如异常告诉您的,您正试图引用一个不存在的属性。<code>Response</code>公开的是<code>.text</code>属性,而不是<code>.txt</code>属性</p>
请先
登录
后评论
针对此问题:
更多的回答
关注
89
关注
收藏
1
收藏,
216
浏览
网友 提问于 2天前
相关Python问题
如何为此数据帧创建散点图?
6 回答
如何为此编写Django模板
4 回答
如何为此表达式编写正则表达式?
6 回答
如何为步进电机选择合适的值?
5 回答
如何为每15分钟间隔的日期时间行(在新列中)添加标签?
7 回答
如何为每一列创建汇总表?
8 回答
如何为每一组groupbyPandas做滚动“得到假人”
8 回答
如何为每一行分别运行函数(python)?
8 回答
如何为每一行生成一个随机数?
10 回答
如何为每一轮将pytorch模型输出存储到numpy
7 回答
如何为每个.py-fi文件创建单独的zip文件
9 回答
如何为每个<li class=”“><a>找到最近的上述同级<li>?
8 回答
如何为每个CSV列生成特定的文件?
9 回答
如何为每个csv文件使用read_csv,即使它是空的?PythonPandas
7 回答
如何为每个CSV文件创建单独的Pandas数据帧并给它们起有意义的名称?
9 回答
如何为每个datetime和每个id创建一行?
2 回答
如何为每个Django型号选择赋予不同的颜色
2 回答
如何为每个Django模型实例安排一个周期性的芹菜任务?
4 回答
如何为每个Django视图设置一个装饰器?
3 回答
如何为每个for循环迭代分配变量
5 回答