May-26-2024, 05:05 AM
(This post was last modified: May-26-2024, 09:18 AM by Pedroski55.)
I don't know what openai does, so I skipped that part.
import requests from bs4 import BeautifulSoup def search_ingredient_price(ingredient): search_url = f"https://www.ah.nl/zoeken?query={ingredient.replace(' ', '%20')}" response = requests.get(search_url) soup = BeautifulSoup(response.text, 'html.parser') try: product = soup.find('div', class_='product-card-portrait') if product: price = product.find('span', class_='price-amount').text.strip().replace(',', '.').replace('€', '') return float(price) else: return 0.0 except AttributeError: return 0.0 def get_ingredient_prices(ingredients): prices = {} for ingredient in ingredients: prices[ingredient] = search_ingredient_price(ingredient) return pricesNow try this in Idle:
ingrediënten = ['meel', 'kaas', 'tomaten'] get_ingredient_prices(ingrediënten)No indent error:
Output:{'meel': 0.0, 'kaas': 0.0, 'tomaten': 0.0}
Pizza voor het ontbijt!