Нормализация данных, привидение к общему json
This commit is contained in:
15
function.py
15
function.py
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user