forked from hhursev/recipe-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgousto.py
72 lines (53 loc) · 1.94 KB
/
gousto.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from ._abstract import AbstractScraper
from ._utils import get_minutes, get_yields, normalize_string
class Gousto(AbstractScraper):
@classmethod
def host(cls):
return "gousto.co.uk"
def title(self):
return self.soup.find("h1", {"class": "indivrecipe-title"}).get_text()
def total_time(self):
return get_minutes(
self.soup.find("p", {"class": "recipehighlight-box-value"}).parent
)
def yields(self):
yields = (
self.soup.find("div", {"id": "ingredients"})
.find("div", {"class": "panel-subheading"})
.get_text()
)
return get_yields("{} servings".format(yields))
def ingredients(self):
# TODO: Fix append
container = self.soup.find("div", {"id": "ingredients"})
ingredients = container.find_all(
"figcaption", {"class": "indivrecipe-ingredients-text"}
)
extras = (
container.find("div", {"class": "panel indivrecipe-panel"})
.find("div", {"class": "panel-subheading"})
.get_text()
)
extras = extras.strip().split(", ")
ingredients = [
normalize_string(ingredient.get_text()) for ingredient in ingredients
]
for extra in extras:
ingredients.append(extra)
return ingredients
def instructions(self):
instructions = self.soup.find("div", {"id": "instructions"}).find_all(
"div", {"class": "indivrecipe-cooking-text-wrapper"}
)
instr_container = [
p.get_text() for subdiv in instructions for p in subdiv.findAll("p")
]
return "\n".join(
normalize_string(instruction) for instruction in instr_container
)
def ratings(self):
ratings = self.soup.find("div", {"class": "star-overflow"}).find(
"img", alt=True
)
rating = int(ratings["alt"][0])
return rating