def main(): resp = requests.get('https://food.mthai.com/food-recipe/page/3') selector = 'h3.entry-title' html_page = bs4.BeautifulSoup(resp.text, 'html.parser') menu_elm = html_page.select(selector) menus = [] for elm in menu_elm: recipe = Recipe() found_elm = elm.findAll('a', attrs={ 'href': re.compile('^https://'), 'rel': 'bookmark' }) if len(found_elm) > 0 and re.search('^(สูตร|วิธีทำ)', found_elm[0].text): recipe.name = found_elm[0].text.strip() recipe.link = found_elm[0].get('href') recipe.food_ingredients = find_food_ingredients( recipe.name, recipe.link) menus.append(recipe) menu_input = input('Enter menu: ') print('\nProcessing...\n') forecast_prices = find_forecast_items_price() for menu in menus: if menu.name == menu_input.strip(): fixed_prices = read_fixed_price() summary_price = {'avg': 0, 'min': 0, 'max': 0} for recipe in menu.food_ingredients: found_forecase_item = False for key in forecast_prices: if forecast_prices[key]['success'] and re.search( '(เนื้อหมู|เนื้อวัว|เนื้อไก่|นม)', forecast_prices[key]['item']): found_forecase_item = True summary_price['avg'] += (forecast_prices[key]['avg'] * recipe.get_gram()) / 1000 summary_price['min'] += (forecast_prices[key]['min'] * recipe.get_gram()) / 1000 summary_price['max'] += (forecast_prices[key]['max'] * recipe.get_gram()) / 1000 break if forecast_prices[key]['success'] and re.search( 'ไข่', forecast_prices[key]['item']): found_forecase_item = True summary_price['avg'] += forecast_prices[key][ 'avg'] * recipe.quantity summary_price['min'] += forecast_prices[key][ 'min'] * recipe.quantity summary_price['max'] += forecast_prices[key][ 'max'] * recipe.quantity break if found_forecase_item: continue for item, price in fixed_prices: if re.search(rf"{item}", recipe.item): summary_price['avg'] += (price * recipe.get_gram()) / 1000 summary_price['min'] += (price * recipe.get_gram()) / 1000 summary_price['max'] += (price * recipe.get_gram()) / 1000 print('cost average: {}, min: {}, max: {}'.format( round(summary_price['avg'], 2), round(summary_price['min'], 2), round(summary_price['max'], 2))) return None print('Your menu doesn\'t exist')