text_plain_output_1.png
from bs4 import BeautifulSoup

from recipe_scrapers import scrape_me

import pandas as pd

import re

URLs = ['https://www.allrecipes.com/recipes/721/world-cuisine/european/french/', 'https://www.allrecipes.com/recipes/16126/world-cuisine/european/french/french-bread/', 'https://www.allrecipes.com/recipes/17138/world-cuisine/european/french/main-dishes/', 'https://www.allrecipes.com/recipes/1857/world-cuisine/european/french/main-dishes/pork/', 'https://www.allrecipes.com/recipes/1858/world-cuisine/european/french/main-dishes/chicken/', 'https://www.allrecipes.com/recipes/1828/world-cuisine/european/french/desserts/', 'https://www.allrecipes.com/recipes/1829/world-cuisine/european/french/soups-and-stews/', 'https://www.allrecipes.com/recipes/1848/world-cuisine/european/french/appetizers/']

recipes_urls = {}
for u in URLs:
    lst_var = []
    url = u
    res = requests.get(url).text
    soup = BeautifulSoup(res, 'html.parser')
    name_ = soup.find_all('h1', class_='comp mntl-taxonomysc-heading mntl-text-block')
    try:
        for i in range(len(soup.find_all('a', class_='comp card--image-top mntl-card-list-items mntl-document-card mntl-card card card--no-image'))):
            url = soup.find_all('a', class_='comp card--image-top mntl-card-list-items mntl-document-card mntl-card card card--no-image')[i]['href']
            lst_var.append(url)
    except:
        pass
    for i in range(len(soup.find_all('a', class_='comp mntl-card-list-items mntl-document-card mntl-card card card--no-image'))):
        url = soup.find_all('a', class_='comp mntl-card-list-items mntl-document-card mntl-card card card--no-image')[i]['href']
        lst_var.append(url)
    recipes_urls[name_[0].text[1:]] = lst_var
len(recipes_urls)

recipes = {}    
i = 0
for name,url_list in recipes_urls.items():
    temp_dict = {}    
    for url in url_list:
        recipe = {}
        scraper = scrape_me(url)
        recipe["Contient"] = "Europe"
        recipe["Country_State"] = "France"
        try:
            recipe["cuisine"] = name
        except:
            recipe["cuisine"] = float("nan")
        try:
            recipe["title"] = scraper.title()
        except:
            recipe["title"] = float("nan")
        try:
            recipe["URL"] = url
        except:
            recipe["URL"] = float("nan")
        try:
            recipe["rating"] = scraper.ratings()
        except:
            recipe["rating"]  = float("nan")
        try:
            recipe["total_time"]= scraper.total_time()
        except:
            recipe["total_time"] = float("nan")
        try:
            recipe["prep_time"] = scraper.prep_time()
        except:
            recipe["prep_time"] = float("nan")
        try:
            recipe["cook_time"] = scraper.cook_time()
        except:
            recipe["cook_time"] = float("nan")
        try:
            recipe["description"] = scraper.description()
        except:
            recipe["description"] = float("nan")
        try:
            recipe["ingredients"] = scraper.ingredients()
        except:
            recipe["ingredients"] = float("nan")
        try:
            recipe["instructions"] = scraper.instructions_list()
        except:
            recipe["instructions"] = float("nan")
        try:
            recipe["nutrients"] = scraper.nutrients()
        except:
            recipe["nutrients"] = float("nan")
        try:
            recipe["serves"] = scraper.yields()
        except:
            recipe["serves"] = float("nan")
        try:
            res = requests.get(url).text
            soup = BeautifulSoup(res,"html.parser")
            rate = soup.find("div",class_ = "comp type--squirrel mntl-recipe-review-bar__rating-count mntl-text-block")
            pattern = r'[0-9,]+'
            s = rate.text
            match = re.search(pattern, s)
            if match:
                number = int(match.group().replace(',', ''))
            recipe["rating_count"] = number
        except:
            recipe["rating_count"] = 0
        time.sleep(1)
        recipes[f"{i}"] = recipe
        i+=1

df_France = pd.DataFrame()
for data in recipes.keys():
    df_France = df_France.append(recipes.get(data), ignore_index=True)

df_France.head(5)