From 61acbb000537e0e2bf91a6ccac13bfe3dddb8f87 Mon Sep 17 00:00:00 2001 From: Chris Pinkney Date: Tue, 3 Nov 2020 00:41:30 -0500 Subject: [PATCH] fixes issue-17: adds thatlowcarblife.com --- parsers/__init__.py | 4 +++- parsers/thatlowcarblife.py | 39 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 parsers/thatlowcarblife.py diff --git a/parsers/__init__.py b/parsers/__init__.py index 53b01ea..3c1a1d3 100644 --- a/parsers/__init__.py +++ b/parsers/__init__.py @@ -15,6 +15,7 @@ from parsers.thewoksoflife import Thewoksoflife from parsers.glebekitchen import GlebeKitchen from parsers.akispetretzikis import AkisPetretzikis from parsers.hervecuisine import Hervecuisine +from parsers.thatlowcarblife import ThatLowCarbLife # Must exclude the "www" portion of the URL PARSERS = { @@ -33,7 +34,8 @@ PARSERS = { 'thewoksoflife.com': Thewoksoflife, 'glebekitchen.com': GlebeKitchen, 'akispetretzikis.com': AkisPetretzikis, - 'hervecuisine.com': Hervecuisine + 'hervecuisine.com': Hervecuisine, + 'thatlowcarblife.com': ThatLowCarbLife, } def getParser(domain): diff --git a/parsers/thatlowcarblife.py b/parsers/thatlowcarblife.py new file mode 100644 index 0000000..fd51792 --- /dev/null +++ b/parsers/thatlowcarblife.py @@ -0,0 +1,39 @@ +from parsers.recipe import Recipe + +class ThatLowCarbLife(Recipe): + + def scrape_recipe(self, soup): + recipe = {} + + name = soup.find('h2', {'class': 'mv-create-title'}) + recipe['name'] = name.contents[0] + + description = soup.find('div', {'class': 'mv-create-description'}) + recipe['description'] = description.contents[0].text + + image = soup.find('header', {'class': 'mv-create-header'}) + recipe['image'] = image.contents[1]['src'] + + recipe['ingredients'] = [] + ingredients = soup.find('div', {'class': 'mv-create-ingredients'}).find('ul').findChildren('li') + for li in ingredients: + recipe['ingredients'].append(li.text) + + recipe['instructions'] = [] + instructions = soup.find('div', {'class': 'mv-create-instructions'}).find('ol').findChildren('li') + for li in instructions: + recipe['instructions'].append(li.text) + + return recipe + + + def Parse(self, url): + recipe = {} + recipe['url'] = url + recipe['source'] = 'thatlowcarblife.com' + + soup = self.fetch_soup(url) + parsed_recipe = self.scrape_recipe(soup) + recipe.update(parsed_recipe) + + return recipe \ No newline at end of file