Python 为什么BeautifulSoup(…).find(…)返回None?

Python 为什么BeautifulSoup(…).find(…)返回None?,python,Python,我对代码有一些问题(我使用bs4): 错误是: temp = data.find("div", class_="BNeawe").text AttributeError: 'NoneType' object has no attribute 'text' 你能帮我找到数据吗?find(“div”,class=“BNeawe”)没有返回任何东西,所以我相信自从你上次成功运行此代码以来,谷歌改变了它显示天气的方式 如果您搜索自己的“Weather in{pl

我对代码有一些问题(我使用bs4):

错误是:

temp = data.find("div", class_="BNeawe").text
AttributeError: 'NoneType' object has no attribute 'text'
你能帮我找到数据吗?find(“div”,class=“BNeawe”)没有返回任何东西,所以我相信自从你上次成功运行此代码以来,谷歌改变了它显示天气的方式

如果您搜索自己的“Weather in{place}”,然后右键单击Weather小部件并选择
Inspect Element
(取决于浏览器),您可以查看数据在页面中的位置,并查看数据所在的类别


它以前似乎在
BNeawe
类下。

您编写的一些代码与动态搜索的结果相反。2天前在搜索中弹出的东西不一定每次都在那里。请尝试打印响应文本。它找不到2天前出现的
div
标记。这就是产生错误的原因。从错误来看,网站似乎已经更改,这意味着可能类名已经更改,因为没有返回任何内容。我建议你再检查一下html文件,或者给我们完整的代码,这样我们就可以这样做。这就是我发现的:'19'但是任何类都不起作用。你可以尝试使用
temp=data.find(“div”,class=“TVtOme”).text
?我想你想要这页上的温度?是的,我想要。我也犯了同样的错误。是的,我想要temperatureOk,我刚刚在replit.com上使用
temp=data.find(“div”,class=“BNeawe”).text运行了几乎完全相同的代码副本,它对我来说运行良好。我不知道该怎么帮你。你一定少了什么。您的请求对象
r
或返回的数据可能有错误。添加到您的代码
print(r)
print(data)
中,查看是否有任何问题
temp = data.find("div", class_="BNeawe").text
AttributeError: 'NoneType' object has no attribute 'text'