Ошибка при парсинге на bs4
Код:
import requests
from bs4 import BeautifulSoup
URL = "https://www.rbc.ru/politics/"
page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")
title = soup.find_all(class_="item__title rm-cm-item-text js-rm-central-column-item-text").text()
print(title)
Traceback (most recent call last):
File "c:\Users\markm\OneDrive\Рабочий стол\News\main.py", line 10, in <module>
title = soup.find_all(class_="item__title rm-cm-item-text js-rm-central-column-item-text").text()
File "C:\Users\markm\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\bs4\element.py", line 2428, in __getattr__
raise AttributeError(
AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?```
Источник: Stack Overflow на русском