-
Notifications
You must be signed in to change notification settings - Fork 544
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds support for waitrose.com (#869)
- Loading branch information
Showing
5 changed files
with
1,400 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# mypy: allow-untyped-defs | ||
|
||
from ._abstract import AbstractScraper | ||
from ._utils import normalize_string | ||
|
||
|
||
class Waitrose(AbstractScraper): | ||
@classmethod | ||
def host(cls): | ||
return "waitrose.com" | ||
|
||
def author(self): | ||
return "waitrose.com" | ||
|
||
def title(self): | ||
return self.schema.title() | ||
|
||
def total_time(self): | ||
return self.schema.total_time() | ||
|
||
def yields(self): | ||
return self.schema.yields() | ||
|
||
def image(self): | ||
img_tag = self.soup.find("img", {"itemprop": "image"}) | ||
if img_tag: | ||
url = img_tag.get("src") | ||
return url[2:] if url.startswith("//") else url | ||
|
||
def ingredients(self): | ||
ingredients_div = self.soup.find("div", {"class": "ingredients"}) | ||
|
||
if ingredients_div: | ||
ingredient_items = ingredients_div.find_all("li") | ||
ingredient_text = [ | ||
normalize_string(item.get_text()) | ||
for item in ingredient_items | ||
if item.get_text() | ||
] | ||
return ingredient_text | ||
|
||
def extract_instructions(self): | ||
instructions_div = self.soup.find("div", {"class": "ingredients"}) | ||
|
||
if instructions_div: | ||
instruction_items = instructions_div.find_all("li") | ||
instruction_text = [ | ||
normalize_string(item.get_text()) | ||
for item in instruction_items | ||
if item.get_text() | ||
] | ||
return "\n".join(instruction_text) | ||
|
||
def ratings(self): | ||
return self.schema.ratings() | ||
|
||
def description(self): | ||
return self.schema.description() |
Oops, something went wrong.