Смотрите, мне необходимо применить find_all в find. Как это сделать, можно ли вообще?
Вот код:
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('li', class_='hor-menu__item has-subm')
tovari = []
for item in items:
tovari.append(
{
'karegoria': item.find('a', class_='hor-menu__lnk').find('span', class_='hor-menu__text').get_text(),
'podkategoria': item.find('div', class_='hor-menu__submenu mega').find('div', class_='mega-m').find('ul', class_='mega-m__inner').find_all('li', class_='mega-m__item').find('div', class_='menu-categ').find('div', class_='menu-categ__header').find('a', class_='menu-categ__title').find('div', class_='menu-categ__title-text').get_text()
}
)
return tovari
html = get_html(URL)
print(get_content(html.text))
Вот ошибка:
Traceback (most recent call last):
File "C:/Users/Я/AppData/Local/Programs/Python/Python38-32/gg.py", line 36, in
print(get_content(html.text))
File "C:/Users/Я/AppData/Local/Programs/Python/Python38-32/gg.py", line 27, in get_content
'podkategoria': item.find('div', class_='hor-menu__submenu mega').find('div', class_='mega-m').find('ul', class_='mega-m__inner').find_all('li', class_='mega-m__item').find('div', class_='menu-categ').find('div', class_='menu-categ__header').find('a', class_='menu-categ__title').find('div', class_='menu-categ__title-text').get_text()
File "C:\Users\Я\AppData\Local\Programs\Python\Python38-32\lib\site-packages\bs4\element.py", line 2173, in __getattr__
raise AttributeError(
AttributeError: ResultSet object has no attribute 'find'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
>>>