【发布时间】:2020-11-01 03:25:11
【问题描述】:
这是我第一次来这里!我是 python 新手,我收到错误:“'NoneType' 对象没有属性 getText。” 我正在使用 Requests 和 BeautifulSoup 库。它是关于 chess.com,一个国际象棋网站,您可以在其中下载所有数据游戏。我正在学习网络抓取和数据可视化,我的想法是使用我的信息。代码是:
text = page.text
b = BeautifulSoup(text, 'html.parser')
content = b.find('span', attrs={'class': re.compile("archive-games-game-time")})
content.getText().strip()
“massarov”是我在页面中的用户名。我不知道怎么了。谁能帮帮我?????
【问题讨论】:
-
首先尝试
print(content)看看你得到了什么(那是为了调试)。原因可能是您要查找的内容不存在或找不到 -
b.find返回的值为 None。在尝试使用getText()之前,您需要检查if content is not None:。我的猜测是,你的 find 没有找到你要找的东西。 -
其实我可能已经明白了。您是否也在该页面中登录您的帐户?
标签: python beautifulsoup attributeerror