AttributeError: 'NoneType' object has no attribute 'text'
时间: 2023-09-14 13:07:39 浏览: 123
This error occurs when you try to access the 'text' attribute of a NoneType object, which means the variable or object you are trying to access is None or null.
Here's an example:
```python
response = requests.get('https://www.example.com')
# If the request was successful, the response object will contain the HTML content of the page
if response.status_code == 200:
html_content = response.text
else:
html_content = None
# If the HTML content is not None, print it
if html_content:
print(html_content)
else:
# If the HTML content is None, raise an error
raise AttributeError("'NoneType' object has no attribute 'text'")
```
In this example, the error will be raised if the HTML content is None, which can happen if the request was unsuccessful or if there was an issue with the website.
阅读全文
相关推荐


















