-
Notifications
You must be signed in to change notification settings - Fork 496
/
nutritionbynathalie.py
58 lines (42 loc) · 1.49 KB
/
nutritionbynathalie.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
# mypy: disallow_untyped_defs=False
import re
from ._abstract import AbstractScraper
BULLET_CHARACTER_ORD = 8226
class NutritionByNathalie(AbstractScraper):
ingredientMatch = re.compile(r"Ingredients:")
@classmethod
def host(cls):
return "nutritionbynathalie.com"
def title(self):
return self.soup.find("h1").get_text()
def total_time(self):
return 0
def yields(self):
return None
def image(self):
try:
return self.soup.find("img", {"id": re.compile(r"^innercomp_")})["src"]
except Exception:
return None
def ingredients(self):
ingredients = []
elements = self.soup.find_all(string=self.ingredientMatch)
for outerElement in elements:
title = outerElement.find_parent("p")
if not title:
continue
for element in title.next_siblings:
ingredient = element.get_text()
if len(ingredient) == 0 or ord(ingredient[0]) != BULLET_CHARACTER_ORD:
break
ingredients.append(ingredient[2:])
element = element.nextSibling
return ingredients
def instructions(self):
title = self.soup.find(string="Directions:").find_parent("p")
instructions = []
for child in title.nextSibling.find_all("li"):
instructions.append(child.get_text())
return "\n".join(instructions)
def ratings(self):
return None