Нормализация данных, привидение к общему json
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
.gitignore
|
||||
.idea
|
||||
.venv
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
29
parser.py
29
parser.py
@@ -59,18 +59,33 @@ def pars_recipie(link='https://povar.ru/recipes/slivochnaya_karbonara-73186.html
|
||||
|
||||
main_container = soup.find(class_='cont_area hrecipe')
|
||||
|
||||
#detailed_tags = main_container.find(class_='detailed_tags') #Собираем теги
|
||||
#detailed_tags = f.extract_tags_from_detailed_tags(detailed_tags)
|
||||
name = main_container.find(class_='detailed fn').get_text()
|
||||
|
||||
#ingredients = f.extr_ingredient(main_container) #Собираем ингредиенты
|
||||
#print(ingredients)
|
||||
|
||||
#calories_info = f.extract_nutrition(main_container.find_all(class_='circle')) #БЖУ
|
||||
#print(calories_info)
|
||||
recipies = {'recipes': {}}
|
||||
|
||||
steps = f.extr_steps(main_container)
|
||||
detailed_tags = f.extract_tags_from_detailed_tags(main_container) #Собираем теги
|
||||
print(detailed_tags)
|
||||
|
||||
ingredients = f.extr_ingredient(main_container) #Собираем ингредиенты
|
||||
print(ingredients)
|
||||
|
||||
calories_info = f.extract_nutrition(main_container.find_all(class_='circle')) #БЖУ
|
||||
print(calories_info)
|
||||
|
||||
steps = f.extr_steps(main_container) #Сборка шагов
|
||||
print(steps)
|
||||
|
||||
preview_img = steps[-1]['img']
|
||||
|
||||
recipies['recipes'] = { 'name':name,
|
||||
'preview_img':preview_img,
|
||||
'tags':detailed_tags,
|
||||
'ingredients':ingredients,
|
||||
'nutritional_value':calories_info,
|
||||
'steps':steps}
|
||||
print(recipies)
|
||||
|
||||
|
||||
|
||||
#pars_group(link)
|
||||
|
||||
Reference in New Issue
Block a user