python import requests from bs4 import BeautifulSoup def get_recipe_data(url): response = requests.get(url) soup = BeautifulSoup(response.text, "html.parser") recipe_name = soup.find("h1", class_="recipe-name").text ingredients = soup.find_all("li", class_="recipe-ingredient") steps = soup.find_all("div", class_="recipe-step") return recipe_name, ingredients, steps recipe_name, ingredients, steps = get_recipe_data(url) python import jieba from nltk import pos_tag from nltk.tokenize import word_tokenize def analyze_ingredients(ingredients): tagged_words = pos_tag(ingredient_words) return tagged_words tagged_words = analyze_ingredients(ingredients) python import numpy as np from pint import UnitRegistry ureg = UnitRegistry() def convert_units(ingredients): converted_ingredients = [] for ingredient in ingredients: amount_in_grams = ureg.Quantity(amount, unit) amount_in_ounces = amount_in_grams.to(ureg.ounce) converted = (amount_in_ounces.magnitude, amount_in_ounces.units) converted_ingredients.append(converted) return converted_ingredients converted_ingredients = convert_units(ingredients)


上一篇:
下一篇:
切换中文