Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with food.com scraper #591

Merged
merged 1 commit into from Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 8 additions & 12 deletions recipe_scrapers/food.py
@@ -1,5 +1,4 @@
from ._abstract import AbstractScraper
from ._utils import get_minutes, get_yields, normalize_string


class Food(AbstractScraper):
Expand All @@ -8,22 +7,19 @@ def host(cls):
return "food.com"

def title(self):
return self.soup.find("h1").get_text()
return self.schema.title()

def total_time(self):
return get_minutes(self.soup.find("div", {"class": "recipe-facts__time"}))
return self.schema.total_time()

def yields(self):
return get_yields(
self.soup.find("div", {"class": "recipe-facts__servings"}).get_text()
)
return self.schema.yields()

def ingredients(self):
ingredients = self.soup.findAll("li", {"class": "recipe-ingredients__item"})
def image(self):
return self.schema.image()

return [normalize_string(ingredient.get_text()) for ingredient in ingredients]
def ingredients(self):
return self.schema.ingredients()

def instructions(self):
instructions = self.soup.findAll("li", {"class": "recipe-directions__step"})

return "\n".join([instruction.get_text() for instruction in instructions])
return self.schema.instructions()
10 changes: 5 additions & 5 deletions tests/test_food.py
Expand Up @@ -34,19 +34,19 @@ def test_ingredients(self):
"1 onion, chopped",
"4 carrots, halved lengthwise and cut crosswise into 1-inch pieces",
"4 parsnips, halved lengthwise and cut crosswise into 1-inch pieces",
"1 12 teaspoons salt",
"14 teaspoon fresh ground black pepper",
"1 1/2 teaspoons salt",
"1/4 teaspoon fresh ground black pepper",
"1 split chicken breast",
"1 cup noodles (about 2 ounces)",
"14 cup chopped fresh dill",
"14 cup chopped fresh parsley",
"1/4 cup chopped fresh dill",
"1/4 cup chopped fresh parsley",
],
self.harvester_class.ingredients(),
)

def test_instructions(self):
return self.assertEqual(
"In a large pot, combine the broth, onion, carrots, parsnips, salt, and pepper and bring to a simmer. Add the chicken breasts to the pot and simmer until jfor about 20 minutes, until cooked. Remove the chicken and let rest. When cool enough to handle, remove skin and bones and chop or shred intobite-size pieces.\nWhile chicken is cooling, bring the soup back to a simmer and stir the noodles into the soup. Simmer until the vegetables are tender and the noodles are done, about 5 minutes. Return the chicken pieces to the pot and then stir in the dill and the parsley.",
"In a large pot, combine the broth, onion, carrots, parsnips, salt, and pepper and bring to a simmer. Add the chicken breasts to the pot and simmer until jfor about 20 minutes, until cooked. Remove the chicken and let rest. When cool enough to handle, remove skin and bones and chop or shred intobite-size pieces.\nWhile chicken is cooling, bring the soup back to a simmer and stir the noodles into the soup. Simmer until the vegetables are tender and the noodles are done, about 5 minutes. Return the chicken pieces to the pot and then stir in the dill and the parsley.",
self.harvester_class.instructions(),
)

Expand Down