forked from hhursev/recipe-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththehappyfoodie.py
51 lines (42 loc) · 1.51 KB
/
thehappyfoodie.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
from ._abstract import AbstractScraper
from ._utils import normalize_string, get_minutes
class TheHappyFoodie(AbstractScraper):
@classmethod
def host(self):
return 'thehappyfoodie.co.uk'
def title(self):
return self.soup.find('h1', {'class': 'main-title'}).get_text()
def total_time(self):
return get_minutes(self.soup.find(
'div', {'class': 'recipe__data__total-time'}
)) or sum([
get_minutes(self.soup.find('div', {'class': 'recipe__data__prep-time'})),
get_minutes(self.soup.find('div', {'class': 'recipe__data__cook-time'}))
])
def ingredients(self):
ingredients = self.soup.find(
'table', {'class': 'recipe__ingredients-table'}
).findAll('tr')
ingredients = [
(
ingredient.find(
'td', {'class': 'recipe__ingredients__amount'}
).get_text(),
ingredient.find(
'td', {'class': 'recipe__ingredients__name'}
).get_text(),
)
for ingredient in ingredients
]
return [
normalize_string('{} {}'.format(amount, name))
for amount, name in ingredients
]
def instructions(self):
instructions = self.soup.find(
'div', {'class': 'recipe__instructions'}
).findAll('p')
return '\n'.join(
normalize_string(instruction.get_text())
for instruction in instructions
)