Ching 9787a6230d
All checks were successful
continuous-integration/drone/push Build is passing
feat(api): 增加从下厨房复制菜谱的功能
2024-03-04 01:56:10 +08:00

21 lines
862 B
Python

import requests
import bs4
ua = 'Mozilla/5.0.html (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.html.2171.71 Safari/537.36'
def get_recipe_from_xiachufang(url):
headers = {'User-Agent': ua}
response = requests.get(url, headers=headers)
response.raise_for_status()
soup = bs4.BeautifulSoup(response.text, 'html.parser')
name = soup.find('h1', class_='page-title').text.strip()
ingredients = []
for ingredient in soup.find('div', class_='ings').find('table').find_all('tr'):
ingredients.append(' / '.join([td.text.strip() for td in ingredient.find_all('td')]))
steps = []
for step in soup.find('div', class_='steps').find('ol').find_all('li'):
steps.append([step.find('p').text.strip(), step.find('img')['src']])
return {'name': name, 'ingredients': ingredients, 'steps': steps}