简体   繁体   English

AttributeError:'NoneType'对象没有属性'text'?

[英]AttributeError: 'NoneType' object has no attribute 'text'?

I'm fairly new to python and only have a couple hours of experience. 我是python的新手,只有几个小时的经验。 I've been creating a script that scrapes the Air Quality readings for my country directly. 我一直在创建一个脚本,直接抓取我所在国家的空气质量读数。

I am trying to run this command within my script: 我正在尝试在脚本中运行以下命令:

psi = soup.find("div", {"class": "panel-stats-value-content"}).text

Though when I run it, it responds with: 虽然当我运行它时,它的响应是:

AttributeError: 'NoneType' object has no attribute 'text'

How can I fix this? 我怎样才能解决这个问题? So that .text will work? 这样该.text将起作用?

This error is raised because BeautifulSoup.find() is unable to find any div elements with the class of panel-stats-value-content in the document, so returns NoneType . 出现此错误是因为BeautifulSoup.find()无法在文档中找到任何具有panel-stats-value-content类的div元素,因此返回NoneType

When you try and call a method on a NoneType , it will raise the above error, but with the method whatever you called on it. 当您尝试在NoneType上调用方法时,它将引发以上错误,但是无论您在该方法上调用了什么方法。

To fix this you need to make sure that the div element's class is correct. 要解决此问题,您需要确保div元素的类正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:'NoneType'对象没有属性'text'-元组 - AttributeError: 'NoneType' object has no attribute 'text' - tuples AttributeError:'NoneType'对象没有属性'text'kivy - AttributeError: 'NoneType' object has no attribute 'text' kivy AttributeError:“ NoneType”对象在python中没有属性“ text” - AttributeError: 'NoneType' object has no attribute 'text' in python BeautifulSoup: AttributeError: 'NoneType' 对象没有属性 'text' - BeautifulSoup: AttributeError: 'NoneType' object has no attribute 'text' 错误:AttributeError:'NoneType' 对象没有属性 'text' - Error: AttributeError: 'NoneType' object has no attribute 'text' (Python) AttributeError: 'NoneType' 对象没有属性 'text' - (Python) AttributeError: 'NoneType' object has no attribute 'text' AttributeError: 'NoneType' object 没有属性 'text' - - AttributeError: 'NoneType' object has no attribute 'text' - AttributeError: 'NoneType' 对象没有属性 'text' BeautifulSoup - AttributeError: 'NoneType' object has no attribute 'text' BeautifulSoup AttributeError: 'NoneType' object 没有属性 'text' - BeautifulShop - AttributeError: 'NoneType' object has no attribute 'text' - BeautifulShop AttributeError:'NoneType'对象没有属性'text'-python - AttributeError: 'NoneType' object has no attribute 'text' - python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM