diff --git a/README.rst b/README.rst index a6150fd6b..dc4190e40 100644 --- a/README.rst +++ b/README.rst @@ -100,6 +100,7 @@ Scrapers available for: - `https://aflavorjournal.com/ `_ - `https://ah.nl/ `_ - `https://akispetretzikis.com/ `_ +- `https://aldi.com.au/ `_ - `https://alexandracooks.com/ `_ - `https://alittlebityummy.com/ `_ - `https://allrecipes.com/ `_ diff --git a/recipe_scrapers/__init__.py b/recipe_scrapers/__init__.py index 98fd24947..3490c8f10 100644 --- a/recipe_scrapers/__init__.py +++ b/recipe_scrapers/__init__.py @@ -17,6 +17,7 @@ from .aflavorjournal import AFlavorJournal from .akispetretzikis import AkisPetretzikis from .albertheijn import AlbertHeijn +from .aldi import Aldi from .alexandracooks import AlexandraCooks from .alittlebityummy import ALittleBitYummy from .allrecipes import AllRecipes @@ -364,6 +365,7 @@ AfghanKitchenRecipes.host(): AfghanKitchenRecipes, AkisPetretzikis.host(): AkisPetretzikis, AlbertHeijn.host(): AlbertHeijn, + Aldi.host(): Aldi, AlexandraCooks.host(): AlexandraCooks, AllRecipes.host(): AllRecipes, AllTheHealthyThings.host(): AllTheHealthyThings, diff --git a/recipe_scrapers/aldi.py b/recipe_scrapers/aldi.py new file mode 100644 index 000000000..1bcd68fc6 --- /dev/null +++ b/recipe_scrapers/aldi.py @@ -0,0 +1,74 @@ +# mypy: allow-untyped-defs +import re + +from ._abstract import AbstractScraper +from ._utils import get_minutes, get_yields + + +class Aldi(AbstractScraper): + @classmethod + def host(cls): + return "aldi.com.au" + + def site_name(self): + return "Aldi" + + def author(self): + return self.soup.find("meta", {"name": "author"}).get("content") + + def title(self): + return self.soup.find("h1").text + + def category(self): + element = self.soup.select_one("a.tab-nav--link.dropdown--list--link.m-active") + if element: + title = element.text + recipe_position = title.find(" Recipe") + if recipe_position != -1: + return title[:recipe_position] + + def prep_time(self): + return get_minutes(self._get_value(re.compile("prep", re.IGNORECASE))) + + def cook_time(self): + return get_minutes(self._get_value(re.compile("cook", re.IGNORECASE))) + + def total_time(self): + return (self.prep_time() or 0) + (self.cook_time() or 0) + + def yields(self): + value = self._get_value(re.compile("(makes)|(serves)", re.IGNORECASE)) + return get_yields(str(value)) + + def image(self): + figure = self.soup.find( + "figure", {"class": "csc-textpic-image csc-textpic-last"} + ) + if figure: + image = figure.find("img") + if image: + return image.get("src") + return None + + def ingredients(self): + h2 = self.soup.find("h2", string=re.compile("Ingredients")) + list_element = h2.find_next_sibling("ul") + ingredients = [] + for li in list_element.find_all("li"): + ingredients.append(li.text.strip()) + return ingredients + + def instructions(self): + list_element = self.soup.find("ol") + return "\n".join(li.text.strip() for li in list_element.find_all("li")) + + def _get_value(self, label): + label_element = self.soup.find("b", string=label) + if label_element: + parts = [ + sibling.strip() + for sibling in label_element.find_next_siblings(string=True) + if sibling.strip() + ] + return " ".join(parts) + return None diff --git a/tests/test_data/aldi.com.au/aldi.json b/tests/test_data/aldi.com.au/aldi.json new file mode 100644 index 000000000..574082517 --- /dev/null +++ b/tests/test_data/aldi.com.au/aldi.json @@ -0,0 +1,40 @@ +{ + "author": "ALDI AU", + "canonical_url": "https://www.aldi.com.au/recipes/breakfast-recipes/overloaded-cheese-toastie-recipe/", + "host": "aldi.com.au", + "image": "https://www.aldi.com.au/fileadmin/_processed_/8/b/csm_1000340_WK23_PD_455x315__OVERLOADED-CHEESE-TOASTIE__1_RET_4506d46579.jpg", + "category": "Breakfast", + "ingredients": [ + "1 tbsp Remano pesto", + "1 slice Westacre tasty cheese", + "3 slices tomato", + "2 slices sourdough bread", + "Handful of The Fresh Salad Co baby spinach" + ], + "ingredient_groups": [ + { + "purpose": null, + "ingredients": [ + "1 tbsp Remano pesto", + "1 slice Westacre tasty cheese", + "3 slices tomato", + "2 slices sourdough bread", + "Handful of The Fresh Salad Co baby spinach" + ] + } + ], + "instructions": "Preheat a sandwich press.\nSpread pesto on one slice of bread and layer with cheese, tomato and spinach and close the sandwich with the remaining slice of bread.\nPlace the sandwich in the press and cook for 3-4 minutes or until the cheese melts and the sandwich is golden brown.\nAllow to cool slightly before serving.", + "instructions_list": [ + "Preheat a sandwich press.", + "Spread pesto on one slice of bread and layer with cheese, tomato and spinach and close the sandwich with the remaining slice of bread.", + "Place the sandwich in the press and cook for 3-4 minutes or until the cheese melts and the sandwich is golden brown.", + "Allow to cool slightly before serving." + ], + "language": "en-AU", + "site_name": "Aldi", + "title": "Overloaded Cheese Toastie Recipe", + "prep_time": 5, + "cook_time": 5, + "total_time": 10, + "yields": "1 serving" +} diff --git a/tests/test_data/aldi.com.au/aldi.testhtml b/tests/test_data/aldi.com.au/aldi.testhtml new file mode 100644 index 000000000..00ff99485 --- /dev/null +++ b/tests/test_data/aldi.com.au/aldi.testhtml @@ -0,0 +1,1235 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Overloaded Cheese Toastie Recipe + + + + + +
+
+ +
+ + + + + + + + + + +
+ +
+
+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + Overloaded Cheese Toastie Recipe + + +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+ + + How to make an Overloaded Cheese Toastie + + +

+ + + + + + + + + + + + + + + + + + + +

Method

  1. Preheat a sandwich press.
  2. Spread pesto on one slice of bread and layer with cheese, tomato and spinach and close the sandwich with the remaining slice of bread.
  3. Place the sandwich in the press and cook for 3-4 minutes or until the cheese melts and the sandwich is golden brown.
  4. Allow to cool slightly before serving.

Option: You can swap out pesto for avocado.

+

Tip: You can use up leftover pesto on grainy crackers, pizza bases, in pasta sauces or with chicken.

+ + + + + + + + + + + + + + + + +
+ + + + + +
+ +
+
+
+ + + + +
+ +
+
+ + + + + + + + + + + + \ No newline at end of file