Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition: Support for rewe.de #1378

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ Scrapers available for:
- `https://recipetineats.com/ <https://www.recipetineats.com/>`_
- `https://redhousespice.com/ <https://redhousespice.com/>`_
- `https://reishunger.de/ <https://www.reishunger.de/>`_
- `https://rewe.de/ <https://www.rewe.de>`_
- `https://rezeptwelt.de/ <https://rezeptwelt.de>`_
- `https://ricetta.it/ <https://ricetta.it>`_
- `https://ricette.giallozafferano.it/ <https://ricette.giallozafferano.it>`_
Expand Down
2 changes: 2 additions & 0 deletions recipe_scrapers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@
from .recipetineats import RecipeTinEats
from .redhousespice import RedHouseSpice
from .reishunger import Reishunger
from .rewe import Rewe
from .rezeptwelt import Rezeptwelt
from .ricetta import Ricetta
from .ricetteperbimby import RicettePerBimby
Expand Down Expand Up @@ -562,6 +563,7 @@
Recept.host(): Recept,
ReceptyPreVas.host(): ReceptyPreVas,
RecipeGirl.host(): RecipeGirl,
Rewe.host(): Rewe,
RicettePerBimby.host(): RicettePerBimby,
SandwhichTribunal.host(): SandwhichTribunal,
SavoryNothings.host(): SavoryNothings,
Expand Down
76 changes: 76 additions & 0 deletions recipe_scrapers/rewe.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import ast
import re

from ._abstract import AbstractScraper

Gamekohl marked this conversation as resolved.
Show resolved Hide resolved

class Rewe(AbstractScraper):
@classmethod
def host(cls):
return "rewe.de"

def language(self):
return self.soup.find("html")["lang"]

def author(self):
return ""
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved

def title(self):
return self.soup.find("h1", {"class": "ld-rds"}).get_text()

def category(self):
return self.soup.find("a", {"id": "nutrition-information-mobile"}).get_text()
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved

def total_time(self):
x_data = self.soup.select_one(
"#recipe-basics>.ld-rds:first-child:first-child div:last-child span:first-child"
).get("x-data")

# Transform the `x-data` string into a dictionary
data_dict = ast.literal_eval(
re.sub(r"(\w+):", r"'\1':", x_data.replace("`", "'"))
)

# Return the "displayText" field
return data_dict["displayText"]
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved

def yields(self):
return self.soup.find("span", {"x-text": "currentServings"}).get_text().strip()

def ingredients(self):
ingredient_list = self.soup.find("ul", {"id": "ingredient_list"})
list_items = ingredient_list.find_all("li", {"class": "ingredient_list_item"})
ingredients = []

for item in list_items:
text = item.find("div", {"class": "ld-rds flex-[1_0_0%]"})
ingredient_text = (
text.get_text(" ", strip=True).replace("\n", "").replace(" ", " ")
)
ingredient_text = re.sub(r"\s+", " ", ingredient_text)

ingredients.append(ingredient_text)

return ingredients

def instructions(self):
step_divs = self.soup.find_all("div", {"class": "step-ingredients"})
steps = []

for step in step_divs:
instruction = step.find(
"div",
{
"class": "ld-rds mt-4 self-stretch text-sm leading-5 text-gray-1000 md:text-base lg:mt-6 lg:leading-6 [&_a:hover]:text-brand-800 [&_a]:underline [&_a]:underline-offset-3"
},
)

steps.append(instruction.get_text().strip())

return "\n".join(steps)

def description(self):
return ""
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved

def canonical_url(self):
return self.soup.find("meta", {"property": "og:url"})["content"]
39 changes: 39 additions & 0 deletions tests/test_data/rewe.de/rewe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"host": "rewe.de",
"canonical_url": "https://www.rewe.de/rezepte/wintergemuese-gnocchi-pfanne-kraeuterdip/",
"site_name": "Rewe.de",
"author": "",
"language": "de",
"title": "Wintergemüse-Gnocchi-Pfanne mit Kräuterdip",
"ingredients": [
"800 g REWE Beste Wahl Gnocchi (Kühlregal)",
"Salz",
"2 rote Zwiebeln",
"0.5 Spitzkohl",
"2 Möhren",
"1 Stange(n) Lauch",
"1 Rote Bete (frisch)",
"50 g REWE Beste Wahl aromatische Walnüsse",
"2 EL Rohrzucker",
"0.5 Bd. Schnittlauch",
"0.5 Bd. Petersilie",
"400 g Quark (Halbfettstufe)",
"Pfeffer",
"Zitronensaft",
"1 Prise(n) Zucker",
"3 EL Rapsöl",
"Muskatnuss"
],
"instructions_list": [
"Gnocchi gegebenenfalls (Packungsanweisung beachten) in Salzwasser al dente kochen.",
"Zwiebeln schälen, in feine Streifen schneiden. Kohl putzen, in Streifen schneiden. Möhren schälen und stifteln. Lauch der Länge nach halbieren, gut waschen und in halbe Ringe schneiden. Rote Bete schälen und in dünne Scheiben hobeln.",
"Walnüsse grob hacken und mit Rohrzucker in einer Pfanne unter Rühren rösten, sodass der Zucker leicht karamellisiert.",
"Für den Dip Kräuter hacken und unter den Quark rühren. Dip mit Salz, Pfeffer, Zitronensaft und einer Prise Zucker abschmecken.",
"2 EL Öl in einer großen Pfanne erhitzen, das Gemüse portionsweise, außer der roten Bete, unter Rühren 5 Minuten garen, sodass es gar ist aber noch leichten Biss hat. Mit Salz, Pfeffer und Muskatnuss würzen.",
"Gemüse aus der Pfanne nehmen und Gnocchi im restlichen Öl kurz goldbraun braten. Dann das Gemüse, inklusive Rote Bete, wieder zugeben, mischen und nochmals mit Salz und Pfeffer würzen. Mit Walnüssen und Dip servieren."
],
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved
"total_time": "45min",
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved
Gamekohl marked this conversation as resolved.
Show resolved Hide resolved
"yields": "4",
"image": "https://c.rewe-static.de/31535699/6/31535699.png",
"description": ""
}
Loading
Loading