diff --git a/recipe_scrapers/cookwell.py b/recipe_scrapers/cookwell.py index f970324cd..5341f07be 100644 --- a/recipe_scrapers/cookwell.py +++ b/recipe_scrapers/cookwell.py @@ -1,7 +1,27 @@ from ._abstract import AbstractScraper +import re class CookWell(AbstractScraper): @classmethod def host(cls): return "cookwell.com" + + def nutrients(self): + nutrition_pattern = re.compile( + r'{\\"calories\\":(?P\d+),\\"carbohydrates\\":(?P\d+),\\"fat\\":(?P\d+),\\"protein\\":(?P\d+)}' + ) + + nutrition_script = self.soup.find("script", string=nutrition_pattern) + if nutrition_script: + match = nutrition_pattern.search(nutrition_script.string) + if match: + nutrition_info = match.groupdict() + return { + "calories": nutrition_info["calories"], + "carbohydrateContent": f'{nutrition_info["carbohydrates"]} g', + "fatContent": f'{nutrition_info["fat"]} g', + "proteinContent": f'{nutrition_info["protein"]} g', + } + + return self.schema.nutrients() diff --git a/tests/test_data/cookwell.com/cookwell_1.json b/tests/test_data/cookwell.com/cookwell_1.json index 25396a84e..1ffbfa7a5 100644 --- a/tests/test_data/cookwell.com/cookwell_1.json +++ b/tests/test_data/cookwell.com/cookwell_1.json @@ -28,7 +28,10 @@ "total_time": 75, "cuisine": "American", "nutrients": { - "calories": "970 calories" + "calories": "970", + "fatContent": "60 g", + "carbohydrateContent": "100 g", + "proteinContent": "12 g" }, "image": "https://cdn.sanity.io/images/g1s4qnmz/production/ba9d3d0d5ff9a0f9f17f8e11df7e93b7f3806a48-1000x1000.jpg", "keywords": [ diff --git a/tests/test_data/cookwell.com/cookwell_2.json b/tests/test_data/cookwell.com/cookwell_2.json index c57f3e223..d1420eeb8 100644 --- a/tests/test_data/cookwell.com/cookwell_2.json +++ b/tests/test_data/cookwell.com/cookwell_2.json @@ -33,7 +33,10 @@ "total_time": 30, "cuisine": "Middle Eastern", "nutrients": { - "calories": "2558 calories" + "calories": "2558", + "fatContent": "49 g", + "carbohydrateContent": "402 g", + "proteinContent": "132 g" }, "image": "https://cdn.sanity.io/images/g1s4qnmz/production/3b2a77f0f746cf90c4f7f49a92b39885ada6e9de-3543x3543.jpg", "keywords": [