Repository: hhursev/recipe-scrapers
Pull request #175 (2020-07-01 17:49:14)

Fix line breaks for the `gousto.co.uk` instructions section
I've noticed that the line breaks on the `gousto.co.uk` instructions section are slightly broken. This is a first stab at a possible fix. The current test is broken for now because it's expecting the old line breaks, but if this solution is acceptable I'll go ahead and fix the test.

hhursev: Solution is definitely acceptable and will be merged when tests are updated :) Thanks 🍻 

Patch:
diff --git a/recipe_scrapers/gousto.py b/recipe_scrapers/gousto.py
index 7d9c37cb..e16aa5c7 100644
--- a/recipe_scrapers/gousto.py
+++ b/recipe_scrapers/gousto.py
@@ -5,7 +5,7 @@ from ._utils import get_minutes, normalize_string, get_yields
 class Gousto(AbstractScraper):
 
     @classmethod
-    def host(self):
+    def host(cls):
         return 'gousto.co.uk'
 
     def title(self):
@@ -25,7 +25,7 @@ class Gousto(AbstractScraper):
             'div',
             {'id': 'ingredients'}
         ).find(
-            'div', 
+            'div',
             {'class': 'panel-subheading'}
         ).get_text()
 
@@ -47,11 +47,12 @@ class Gousto(AbstractScraper):
             'div',
             {'class': 'panel-subheading'}
         ).get_text()
-        
+
         extras = extras.strip().split(', ')
 
         ingredients = [
-            normalize_string(ingredient.get_text()) for ingredient in ingredients]
+            normalize_string(ingredient.get_text())
+            for ingredient in ingredients]
 
         for extra in extras:
             ingredients.append(extra)
@@ -67,10 +68,14 @@ class Gousto(AbstractScraper):
             {'class': 'indivrecipe-cooking-text-wrapper'}
         )
 
-        return '\n'.join([
-            normalize_string(instruction.get_text())
-            for instruction in instructions
-        ])
+        instr_container = [p.get_text()
+                           for subdiv in instructions
+                           for p in subdiv.findAll('p')]
+
+        return '\n'.join(
+            normalize_string(instruction)
+            for instruction in instr_container
+        )
 
     def ratings(self):
         ratings = self.soup.find(
@@ -84,4 +89,3 @@ class Gousto(AbstractScraper):
         rating = int(ratings['alt'][0])
 
         return rating
-        
\ No newline at end of file


Test patch:
diff --git a/tests/test_gousto.py b/tests/test_gousto.py
index ccca4288..b4dd5777 100644
--- a/tests/test_gousto.py
+++ b/tests/test_gousto.py
@@ -40,7 +40,7 @@ class TestGoustoScraper(ScraperTest):
 
     def test_instructions(self):
         return self.assertEqual(
-            "Preheat the oven to 200°C/ 180°C (fan)/ 400°F/ Gas 6 Boil a kettle (used in steps 3 & 5)\nAdd 1-2 tbsp of olive oil to a pan on a high heat Once the oil is hot, sear the pork tenderloin for 2 min on each side, or until browned all over (keep the pan for step 6) Season to your taste with salt and pepper\nPlace the pork on an oven-proof tray and put in the oven for 8-10 min, or until cooked through Once done, remove from the oven, cover well and allow to rest until step 7 Dissolve half the (whole) beef stock cube in 100ml (200ml) of boiling water\nCut the mushrooms into quarters Peel the onion(s) and chop finely Crush the garlic with the side of a knife, peel it and chop finely Chop the parsley finely\nCook the pasta in a pot of boiling water and salt (optional) for 8-10 min or until the pasta is cooked to your taste, stirring occasionally, then drain\nReturn the pork pan to a medium-high heat, add the garlic and onion and cook for 1 min Add the mushrooms and cook for 1 min Reduce the heat, add the stock and 50ml (100ml) of cream and simmer for 5 min Add the parsley\nGrate the parmesan Cut the pork into slices (approx. 2cm) Season the mushroom sauce to your taste with salt and pepper\nAdd the pasta to the sauce and mix well Serve the pasta with the pork on top and sprinkle with parmesan Enjoy!",
+            "Preheat the oven to 200°C/ 180°C (fan)/ 400°F/ Gas 6\nBoil a kettle (used in steps 3 & 5)\nAdd 1-2 tbsp of olive oil to a pan on a high heat\nOnce the oil is hot, sear the pork tenderloin for 2 min on each side, or until browned all over (keep the pan for step 6)\nSeason to your taste with salt and pepper\nPlace the pork on an oven-proof tray and put in the oven for 8-10 min, or until cooked through\nOnce done, remove from the oven, cover well and allow to rest until step 7\nDissolve half the (whole) beef stock cube in 100ml (200ml) of boiling water\nCut the mushrooms into quarters\nPeel the onion(s) and chop finely\nCrush the garlic with the side of a knife, peel it and chop finely\nChop the parsley finely\nCook the pasta in a pot of boiling water and salt (optional) for 8-10 min or until the pasta is cooked to your taste, stirring occasionally, then drain\nReturn the pork pan to a medium-high heat, add the garlic and onion and cook for 1 min\nAdd the mushrooms and cook for 1 min\nReduce the heat, add the stock and 50ml (100ml) of cream and simmer for 5 min\nAdd the parsley\nGrate the parmesan\nCut the pork into slices (approx. 2cm)\nSeason the mushroom sauce to your taste with salt and pepper\nAdd the pasta to the sauce and mix well\nServe the pasta with the pork on top and sprinkle with parmesan\nEnjoy!",
             self.harvester_class.instructions(),
         )