forked from hhursev/recipe-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdr.py
57 lines (47 loc) · 1.98 KB
/
dr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# mypy: disallow_untyped_defs=False
from ._abstract import AbstractScraper
from ._utils import normalize_string
class Dr(AbstractScraper):
@classmethod
def host(cls):
return "dr.dk"
def title(self):
title_span = self.soup.find("span", {"class": "dre-title-text"})
return title_span.get_text() if title_span else None
def author(self):
author_div = self.soup.find(
"div", {"class": "dre-byline__contribution-details"}
)
author_span = (
author_div.find("span", {"itemprop": "name"}) if author_div else None
)
return author_span.get_text() if author_span else None
def image(self):
return self.schema.image()
def ingredients(self):
ingredients_divs = self.soup.findAll("div", {"class": "dre-list dre-variables"})
ingredients_list = []
for div in ingredients_divs:
ul = div.find("ul", {"class": "dre-list__list"})
lis = ul.findAll("li", {"class": "dre-list-item"})
for li in lis:
span = li.find("span", {"class": "dre-list-item__content"})
if span:
p = span.find("p")
if p:
ingredients_list.append(normalize_string(p.get_text()))
return ingredients_list
def instructions(self):
fremgangsmade_div = self.soup.find("div", string="Fremgangsmåde")
if fremgangsmade_div:
parent_section = fremgangsmade_div.find_parent("section")
if parent_section:
instructions_list = []
instructions_divs = parent_section.findAll(
"div", {"class": "dre-speech"}
)
for div in instructions_divs:
p = div.find("p", {"class": "dre-article-body-paragraph"})
if p:
instructions_list.append(normalize_string(p.get_text()))
return "\n".join(instructions_list)