diff --git a/recipe_scrapers/usapears.py b/recipe_scrapers/usapears.py index ee97e1ee3..c47a16cdb 100644 --- a/recipe_scrapers/usapears.py +++ b/recipe_scrapers/usapears.py @@ -1,4 +1,7 @@ +import re + from ._abstract import AbstractScraper +from ._exceptions import ElementNotFoundInHtml from ._utils import get_minutes, normalize_string @@ -25,6 +28,31 @@ def ingredients(self): for paragraph in ingredient_elements ] + def nutrients(self): + container = self.soup.find("ul", {"itemprop": "nutrition"}) + if not container: + raise ElementNotFoundInHtml("Could not find nutritional info container") + + results = {} + redundant_pattern = r"(.+)[:] " + for item in container.find_all("li", {"itemprop": True}): + nutrient = item["itemprop"] + content = "".join(str(elem) for elem in item.children) + if re.match(redundant_pattern, content): + content = re.sub(redundant_pattern, "", content) + results[nutrient] = content + + corrections = { + "carbohydrates": "carbohydrateContent", + "protein": "proteinContent", + "fat": "fatContent", + } + for mistake, correction in corrections.items(): + if mistake in results: + results[correction] = results.pop(mistake) + + return results + def ratings(self): try: ratings = self.schema.ratings() diff --git a/tests/test_data/usapears.org/usapears.json b/tests/test_data/usapears.org/usapears.json index fb71e581c..de5e64c82 100644 --- a/tests/test_data/usapears.org/usapears.json +++ b/tests/test_data/usapears.org/usapears.json @@ -23,14 +23,11 @@ "yields": "6 servings", "description": "This simple, tasty pear recipe was created by Chef Jamie Lauren of Absinthe Brasserie and Bar in San Francisco and cookbook author Mollie Katzen. If you can’t find Bosc pears at your local grocery store, red or green Anjou pears also work well.", "total_time": 25, - "ratings": null, - "ratings_count": 4, "nutrients": { - "servingSize": "Serving Size: 1 Pear", - "calories": "Calories: 230", - "carbohydrateContent": "Carbohydrate: 34g", - "proteinContent": "Protein: 5g", - "fiberContent": "Dietary Fiber: 7g" + "servingSize": "1 Pear", + "calories": "230", + "carbohydrateContent": "34g", + "proteinContent": "5g" }, "image": "https://usapears.org/wp-content/uploads/2014/10/Sauteed-Bosc-Pears1.jpg" } diff --git a/tests/test_data/usapears.org/usapears.testhtml b/tests/test_data/usapears.org/usapears.testhtml index d83210b3a..657b2abb8 100644 --- a/tests/test_data/usapears.org/usapears.testhtml +++ b/tests/test_data/usapears.org/usapears.testhtml @@ -1,29 +1,29 @@ - - - - - - - - - - - - - Sauteed Bosc Pears - USA Pears - - - - - - - - - - - + + + + + + + + + + + + + Sauteed Bosc Pears - USA Pears + + + + + + + + + + + @@ -37,952 +37,937 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
-
- -
- -
- - -
- - - - - - - - -
- - -
-
- -
- - - - - - - - -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
- Recipe Image -
-
- -
- -
- - - -
-
- -
-

Sauteed Bosc Pears

-
-
- -
-
-
10
-
Prep Time
-
- -
-
15
-
Cook Time
-
- -
-
6
-
Servings
-
-
- - - -
-
-
-
- -
- - - - -
- -
-
- -
- This simple, tasty pear recipe was created by Chef Jamie Lauren of Absinthe Brasserie and Bar in San Francisco and cookbook author Mollie Katzen. If you can’t find Bosc pears at your local grocery store, red or green Anjou pears also work well.
- - - -
- INGREDIENTS -
- -
- -
    -
  • 2 tablespoons butter
  • -
  • ¼ teaspoon cinnamon
  • -
  • ¼ teaspoon ground nutmeg
  • -
  • ¼ teaspoon ground allspice
  • -
  • 6 Bosc USA Pears, peeled, cored, and quartered
  • -
  • Juice of ½ lemon (about 3 tablespoons)
  • -
  • 1 ½ cup nonfat vanilla yogurt or frozen yogurt
  • -
  • ½ cup chopped, toasted California walnuts
  • -
-
- -
- -
- -
- DIRECTIONS -
- -
-

To prepare pears, melt butter in a large skillet over medium heat. Stir in spices and cook for 30 seconds or until aromatic. Add pears and cook for 15 minutes or until tender, stirring frequently. Stir in lemon juice.

-

Serve with nonfat vanilla yogurt or frozen yogurt and top with walnuts.

-
- - - - - - - -
- NUTRITION -
- -
    - -
  • Serving Size: 1 Pear
  • - -
  • Calories: 230
  • - - - -
  • Carbohydrate: 34g
  • - -
  • Dietary Fiber: 7g
  • - -
  • Protein: 5g
  • - - - -
- - - - - - -
- - -
- - -
-

You May Also Like

- - - - -
-
- - - -
- - - -
- - -
-
1 Comment » for Sauteed Bosc Pears
- - -
    -
  1. -
    -
    - Brittany says:
    - - - -

    -

    This is one of my favorite winter desserts! These sauteed Bosc pears are so delicious in a bowl of chilled almond milk. I like to add a little dried ginger to my pears, too. So healthy and simple!

    - - -
    -
  2. -
- - - - - -
-

Review This Recipe

Your email address will not be published. Required fields are marked *

*

*

- -
- - - - -

- -

- - - - - - -
- - - - - -
- - - - -
-
- -
- - - -
- - - -
- - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+ +
+ +
+ + +
+ + + + + + + + +
+ + +
+
+ +
+ + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+ Recipe Image +
+
+ +
+ +
+ + + +
+
+ +
+

Sauteed Bosc Pears

+
+
+ +
+
+
10
+
Prep Time
+
+ +
+
15
+
Cook Time
+
+ +
+
6
+
Servings
+
+
+ + + +
+
+
+
+ +
+ + + + +
+ +
+
+ +
+ This simple, tasty pear recipe was created by Chef Jamie Lauren of Absinthe Brasserie and Bar in San Francisco and cookbook author Mollie Katzen. If you can’t find Bosc pears at your local grocery store, red or green Anjou pears also work well.
+ + + +
+ INGREDIENTS +
+ +
+ +
    +
  • 2 tablespoons butter
  • +
  • ¼ teaspoon cinnamon
  • +
  • ¼ teaspoon ground nutmeg
  • +
  • ¼ teaspoon ground allspice
  • +
  • 6 Bosc USA Pears, peeled, cored, and quartered
  • +
  • Juice of ½ lemon (about 3 tablespoons)
  • +
  • 1 ½ cup nonfat vanilla yogurt or frozen yogurt
  • +
  • ½ cup chopped, toasted California walnuts
  • +
+
+ + + +
+ DIRECTIONS +
+ +
+

To prepare pears, melt butter in a large skillet over medium heat. Stir in spices and cook for 30 seconds or until aromatic. Add pears and cook for 15 minutes or until tender, stirring frequently. Stir in lemon juice.

+

Serve with nonfat vanilla yogurt or frozen yogurt and top with walnuts.

+
+ + + + + +
NUTRITION
  • Serving Size: 1 Pear
  • Calories: 230
  • Carbohydrates: 34g
  • Protein: 5g
+ + + +
+ + +
+ + +
+

You May Also Like

+ + + + +
+
+ + + +
+ + + +
+ + +
+
1 Comment » for Sauteed Bosc Pears
+ + +
    +
  1. +
    +
    + Brittany says:
    + + + +

    +

    This is one of my favorite winter desserts! These sauteed Bosc pears are so delicious in a bowl of chilled almond milk. I like to add a little dried ginger to my pears, too. So healthy and simple!

    + + +
    +
  2. +
+ + + + + +
+

Review This Recipe

Your email address will not be published. Required fields are marked *

*

*

+ +
+ + + + +

+ +

+ + + + + + +
+ + + + + +
+ + + + +
+
+ +
+ + + +
+ + + +
+ + + - - - - - - - - - - - - - - - - + e.appendChild(s);}()); + + + + + + + + + + + + + + + + + \ No newline at end of file