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' (#632)

The 'text' parameter is still provided but is deprecated; see https://bazaar.launchpad.net/~leonardr/beautifulsoup/bs4/view/head:/CHANGELOG#L546
  • Loading branch information
jayaddison committed Oct 12, 2022
1 parent 401070d commit f5c5ec1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions recipe_scrapers/cookstr.py
Expand Up @@ -17,15 +17,15 @@ def total_time(self):
sections = self.soup.findAll("div", {"class": "articleAttrSection"})
total_time = 0
for section in sections:
time = section.find(text="Total Time")
time = section.find(string="Total Time")
if time:
total_time += get_minutes(time.parent.parent)
return total_time

def yields(self):
sections = self.soup.findAll("span", {"class": "attrLabel"})
for section in sections:
serves = section.find(text="Serves")
serves = section.find(string="Serves")
if serves:
return get_yields(serves.parent.parent)
raise Exception("Servings amount not found")
Expand Down
2 changes: 1 addition & 1 deletion recipe_scrapers/cucchiaio.py
Expand Up @@ -21,7 +21,7 @@ def total_time(self):
return 0

def yields(self):
header = self.soup.find("td", text="PORZIONI")
header = self.soup.find("td", string="PORZIONI")
if header:
value = header.find_next("td")
return get_yields(value)
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/nutritionbynathalie.py
Expand Up @@ -31,7 +31,7 @@ def image(self):
def ingredients(self):
ingredients = []

elements = self.soup.find_all(text=self.ingredientMatch)
elements = self.soup.find_all(string=self.ingredientMatch)
for outerElement in elements:
title = outerElement.find_parent("p")
if not title:
Expand All @@ -47,7 +47,7 @@ def ingredients(self):
return ingredients

def instructions(self):
title = self.soup.find(text="Directions:").find_parent("p")
title = self.soup.find(string="Directions:").find_parent("p")

instructions = []
for child in title.nextSibling.find_all("li"):
Expand Down
8 changes: 4 additions & 4 deletions recipe_scrapers/popsugar.py
Expand Up @@ -13,12 +13,12 @@ def title(self):
return normalize_string(title)

def total_time(self):
anchor = self._context().find(text="Total Time")
anchor = self._context().find(string="Total Time")
time = anchor.parent.findNext("dd").get_text()
return get_minutes(time)

def yields(self):
anchor = self._context().find(text="Yield")
anchor = self._context().find(string="Yield")
serves = anchor.parent.findNext("dd").get_text()
return get_yields(serves)

Expand All @@ -29,7 +29,7 @@ def image(self):
return article

def ingredients(self):
container = self._context().find("h3", text="Ingredients").parent
container = self._context().find("h3", string="Ingredients").parent
entries = container.findAll("li")

ingredients = []
Expand All @@ -51,7 +51,7 @@ def ingredients(self):
return ingredients

def instructions(self):
container = self._context().find("h3", text="Directions").parent
container = self._context().find("h3", string="Directions").parent
return "\n".join([entry.get_text() for entry in container.findAll("li")])

def _context(self):
Expand Down
4 changes: 2 additions & 2 deletions recipe_scrapers/thespruceeats.py
Expand Up @@ -13,14 +13,14 @@ def title(self):

def total_time(self):
return get_minutes(
self.soup.find("span", text="Total: ").find_next_sibling(
self.soup.find("span", string="Total: ").find_next_sibling(
"span", {"class": "meta-text__data"}
)
)

def yields(self):
return (
self.soup.find("span", text="Servings: ")
self.soup.find("span", string="Servings: ")
.find_next_sibling("span", {"class": "meta-text__data"})
.get_text()
)
Expand Down

0 comments on commit f5c5ec1

Please sign in to comment.