Skip to content

Commit

Permalink
Maintenance: update bs4 string searches to use 'string' parameter ins…
Browse files Browse the repository at this point in the history
…tead of 'text' (#638)
  • Loading branch information
jayaddison committed Oct 13, 2022
1 parent 860fb89 commit f55e235
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions recipe_scrapers/farmhousedelivery.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def title(self):

def ingredients(self):
# Style 1
ingredients_marker = self.soup.find("p", text=re.compile(r"Ingredients:"))
ingredients_marker = self.soup.find("p", string=re.compile(r"Ingredients:"))
if ingredients_marker is not None:
ingredients_marker_siblings = ingredients_marker.next_siblings
for ingredients_marker_sibling in ingredients_marker_siblings:
Expand All @@ -37,7 +37,7 @@ def ingredients(self):
]

# Style 2
ingredients_marker = self.soup.find("p", text=re.compile(r"Ingredients"))
ingredients_marker = self.soup.find("p", string=re.compile(r"Ingredients"))
if ingredients_marker is not None:
ingredients = []
ingredients_marker_siblings = ingredients_marker.next_siblings
Expand All @@ -58,7 +58,7 @@ def ingredients(self):

def _instructions_list(self):
# Style 1
instructions_marker = self.soup.find("p", text=re.compile(r"Instructions:"))
instructions_marker = self.soup.find("p", string=re.compile(r"Instructions:"))
if instructions_marker is not None:
instructions_marker_siblings = instructions_marker.next_siblings
for instructions_marker_sibling in instructions_marker_siblings:
Expand All @@ -74,7 +74,7 @@ def _instructions_list(self):
]

# Style 2
instructions_marker = self.soup.find("p", text=re.compile(r"Instructions"))
instructions_marker = self.soup.find("p", string=re.compile(r"Instructions"))
if instructions_marker is not None:
instructions = []
instructions_marker_siblings = instructions_marker.next_siblings
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/fredriksfikaallas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def image(self):

def ingredients(self):
ingredients = []
content = self.soup.find("strong", text=re.compile("Ingredienser"))
content = self.soup.find("strong", string=re.compile("Ingredienser"))

contentRows = content.parent.text.split("\n")

Expand All @@ -43,7 +43,7 @@ def ingredients(self):

def instructions(self):
instructions = []
content = self.soup.find("strong", text=re.compile("Gör så här"))
content = self.soup.find("strong", string=re.compile("Gör så här"))

contentRows = content.parent.text.split("\n")

Expand Down
6 changes: 3 additions & 3 deletions recipe_scrapers/mykitchen101.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).get_text()

def yields(self):
return get_yields(self.soup.find("p", text=re.compile("分量:")).get_text())
return get_yields(self.soup.find("p", string=re.compile("分量:")).get_text())

def image(self):
return self.schema.image()

def ingredients(self):
soup = BeautifulSoup(str(self.soup), features="html.parser")
ingredients = (
soup.find(name="p", text=re.compile("材料:")).find_next("ul").find_all("li")
soup.find(name="p", string=re.compile("材料:")).find_next("ul").find_all("li")
)
return [normalize_string(ingredient.get_text()) for ingredient in ingredients]

def instructions(self):
soup = BeautifulSoup(str(self.soup), features="html.parser")
instructions = soup.find(name="p", text=re.compile("做法:")).find_all_next("p")
instructions = soup.find(name="p", string=re.compile("做法:")).find_all_next("p")
return "\n".join(
[
normalize_string(instruction.get_text())
Expand Down
6 changes: 3 additions & 3 deletions recipe_scrapers/mykitchen101en.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ def title(self):
return self.soup.find("h1", {"class": "entry-title"}).get_text()

def yields(self):
return get_yields(self.soup.find("p", text=re.compile("Yields: ")).get_text())
return get_yields(self.soup.find("p", string=re.compile("Yields: ")).get_text())

def image(self):
return self.schema.image()

def ingredients(self):
soup = BeautifulSoup(str(self.soup), features="html.parser")
ingredients = (
soup.find(name="p", text=re.compile("Ingredients:"))
soup.find(name="p", string=re.compile("Ingredients:"))
.find_next("ul")
.find_all("li")
)
Expand All @@ -36,7 +36,7 @@ def ingredients(self):
def instructions(self):
soup = BeautifulSoup(str(self.soup), features="html.parser")
instructions = soup.find(
name="p", text=re.compile("Directions:")
name="p", string=re.compile("Directions:")
).find_all_next("p")
return "\n".join(
[
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/sunbasket.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def title(self):
return self.soup.find("h1").get_text()

def total_time(self):
minutes_tag = self.soup.find("span", text=re.compile(r"Minutes"))
minutes_tag = self.soup.find("span", string=re.compile(r"Minutes"))
return get_minutes(minutes_tag.parent.get_text())

def yields(self):
yields_tag = self.soup.find("span", text=re.compile(r"Servings,"))
yields_tag = self.soup.find("span", string=re.compile(r"Servings,"))
return get_yields(yields_tag.parent.get_text())

def ingredients(self):
Expand Down

0 comments on commit f55e235

Please sign in to comment.