我正在开发一个新的项目,以摆脱我能做的最基本的事情,我决定研究网页抓取。 我的想法是使用SteamStatus检查Steam的当前状态,并让我的脚本打印它。对于第一个,我使用了蒸汽商店的状态,并编写了以下代码:
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))
这样,我得到了以下错误:
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'
根据我的搜索和发现,这可能是请求模块的过时版本的问题,但我已经确定我有最新版本(2.24.0)
欢迎来到SO
如前面的回答所述,错误与使用错误的属性
.txt
有关,尽管.text
正确最后要注意的是,您试图刮取的页面加载了javascript,因此
requests
不是您要寻找的包。有关使用selenium
webdriver的大致解决方案,请参见下文正如异常告诉您的,您正试图引用一个不存在的属性。
Response
公开的是.text
属性,而不是.txt
属性相关问题 更多 >
编程相关推荐