Нормализация данных, привидение к общему json

This commit is contained in:
zein
2025-11-17 03:16:32 +03:00
parent 305d9be40c
commit 768ab3c4ef
3 changed files with 30 additions and 15 deletions

View File

@@ -40,8 +40,9 @@ def extract_nutrition(calories_info):
except:
return print('БЖУ не найдены')
def extract_tags_from_detailed_tags(detailed_tags):
def extract_tags_from_detailed_tags(main_container):
detailed_tags = main_container.find(class_='detailed_tags')
tags = {}
for span_b in detailed_tags.find_all('span', class_='b'):
@@ -54,7 +55,6 @@ def extract_tags_from_detailed_tags(detailed_tags):
tag_list = []
tags[label] = tag_list
#print(f"{label}: {', '.join(tag_list) if tag_list else '—'}")
return tags
@@ -71,7 +71,7 @@ def try_extr_ingredient(span_b, class_, portions=1):
def extr_ingredient(main_container):
#Сбор ингредиентов
portions = int(main_container.find(class_='yield value').get_text(strip=True))
tags = {}
@@ -94,16 +94,17 @@ def extr_steps(main_container):
main_container = main_container.find_all(class_='stepphotos')
steps = {}
count_step = 0
steps = []
for items in main_container[1:]:
count_step += 1
img = items.get('href')
title = items.get('title')
steps[f'step_{count_step}'] = {'img':img, 'title':title}
steps.append({
'img': img,
'title': title
})
return steps