forked from hhursev/recipe-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbbcgoodfood.py
58 lines (47 loc) · 1.58 KB
/
bbcgoodfood.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
from ._abstract import AbstractScraper
from ._utils import get_minutes, normalize_string, get_yields
class BBCGoodFood(AbstractScraper):
@classmethod
def host(self):
return 'bbcgoodfood.com'
def title(self):
return self.soup.find('h1', {'itemprop': 'name'}).get_text()
def total_time(self):
return sum([
get_minutes(self.soup.find(
'span',
{'class': 'recipe-details__cooking-time-prep'}
).find('span')),
get_minutes(self.soup.find(
'span',
{'class': 'recipe-details__cooking-time-cook'}
).find('span'))
])
def yields(self):
return get_yields(self.soup.find(
'span',
{'class': 'recipe-details__text', 'itemprop': 'recipeYield'}
))
def ingredients(self):
ingredients = self.soup.findAll(
'li',
{'itemprop': "ingredients"}
)
return [
normalize_string(
'{normal_text}{tooltip_text}'.format(
normal_text=ingredient.find(text=True),
tooltip_text=ingredient.find('a').get_text() if ingredient.find('a') is not None else ''
)
)
for ingredient in ingredients
]
def instructions(self):
instructions = self.soup.findAll(
'li',
{'itemprop': 'recipeInstructions'}
)
return '\n'.join([
normalize_string(instruction.get_text())
for instruction in instructions
])