From 028b2dfb22ec56e929b8c078e29b61c260006d48 Mon Sep 17 00:00:00 2001 From: smilerz Date: Sat, 3 Apr 2021 11:12:23 -0500 Subject: [PATCH] added cooksillustrated custom scraper --- cookbook/helper/scrapers/cooksillustrated.py | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 cookbook/helper/scrapers/cooksillustrated.py diff --git a/cookbook/helper/scrapers/cooksillustrated.py b/cookbook/helper/scrapers/cooksillustrated.py new file mode 100644 index 00000000..9a3fb49f --- /dev/null +++ b/cookbook/helper/scrapers/cooksillustrated.py @@ -0,0 +1,56 @@ +import json +from recipe_scrapers._abstract import AbstractScraper + + +class CooksIllustrated(AbstractScraper): + @classmethod + def host(cls): + return "cooksillustrated.com" + + def title(self): + return self.schema.title() + + def image(self): + return self.schema.image() + + def total_time(self): + if not self.recipe: + self.get_recipe() + return self.recipe['recipeTimeNote'] + + def yields(self): + if not self.recipe: + self.get_recipe() + return self.recipe['yields'] + + def ingredients(self): + if not self.recipe: + self.get_recipe() + ingredients = self.recipe['ingredientGroups'][0]['fields']['recipeIngredientItems'] + return [ + "{} {} {}{}".format( + i['fields']['qty'], + i['fields']['measurement'], + i['fields']['ingredient']['fields']['title'], + i['fields']['postText'] + ) + for i in ingredients + ] + + def instructions(self): + if not self.recipe: + self.get_recipe() + return "\n".join([self.recipe['whyThisWorks']] + + [ + instruction['fields']['content'] + for instruction in self.recipe['instructions'] + ] + ) + + def nutrients(self): + raise NotImplementedError("This should be implemented.") + + def get_recipe(self): + j = json.loads(self.soup.find(type='application/json').string) + name = list(j['props']['initialState']['content']['documents'])[0] + self.recipe = j['props']['initialState']['content']['documents'][name]