Repository: hhursev/recipe-scrapers
Pull request #294 (2021-01-09 05:20:43)

SimplyRecipes: Removing double new line between instructions
The pictures between each instruction in the HTML was leading to double new line characters to be added between each step. 


Patch:
diff --git a/recipe_scrapers/simplyrecipes.py b/recipe_scrapers/simplyrecipes.py
index 9cfa6a81..da117985 100644
--- a/recipe_scrapers/simplyrecipes.py
+++ b/recipe_scrapers/simplyrecipes.py
@@ -32,10 +32,15 @@ class SimplyRecipes(AbstractScraper):
         instructions_html = self.soup.find("div", {"class": "instructions"}).findAll(
             "p"
         )
+        instructions = [
+            normalize_string(instruction.get_text())
+            for instruction in instructions_html
+        ]
 
         return "\n".join(
             [
-                normalize_string(instruction.get_text())
-                for instruction in instructions_html
+                instruction
+                for instruction in instructions
+                if instruction and not instruction.isspace()
             ]
         )


Test patch:
diff --git a/tests/test_simplyrecipes.py b/tests/test_simplyrecipes.py
index bd681b62..dc99bf0c 100644
--- a/tests/test_simplyrecipes.py
+++ b/tests/test_simplyrecipes.py
@@ -46,6 +46,6 @@ class TestSimplyRecipesScraper(ScraperTest):
 
     def test_instructions(self):
         return self.assertEqual(
-            "1 Assemble the soup and bring to a simmer: Combine the chicken, white rice, celery, carrots, onions, garlic, salt, and pepper in a large pot. Add the chicken stock and bring to a boil over high heat.\nOnce the soup is boiling, reduce the heat to keep the soup at a gentle simmer.\n\n2 Simmer for about 25 minutes: As the soup simmers, skim off any foam that collects on the surface with a spoon. Continue to simmer until the rice and vegetables are tender, about 25 minutes. Remove the soup from heat.\n3 Shred the chicken and make the garlic paste: Remove the chicken and garlic cloves using a slotted spoon or tongs. Transfer the chicken breasts to a bowl and shred with two forks. Discard the bones. Return the shredded chicken to the pot.\nSmash the garlic cloves into a paste against a cutting board using a fork or the flat of your knife. Stir the paste back into the soup.\n\n4 Season and serve: Stir the lemon juice into to the soup, and taste. The soup should taste rich, barely salty, and with just a hint of lemon. Add more salt or lemon juice as needed until it tastes good to you.\nDivide among bowls and sprinkle with some parsley for serving.\nLeftovers will keep for about a week refrigerated, or up to 3 months frozen.",
+            "1 Assemble the soup and bring to a simmer: Combine the chicken, white rice, celery, carrots, onions, garlic, salt, and pepper in a large pot. Add the chicken stock and bring to a boil over high heat.\nOnce the soup is boiling, reduce the heat to keep the soup at a gentle simmer.\n2 Simmer for about 25 minutes: As the soup simmers, skim off any foam that collects on the surface with a spoon. Continue to simmer until the rice and vegetables are tender, about 25 minutes. Remove the soup from heat.\n3 Shred the chicken and make the garlic paste: Remove the chicken and garlic cloves using a slotted spoon or tongs. Transfer the chicken breasts to a bowl and shred with two forks. Discard the bones. Return the shredded chicken to the pot.\nSmash the garlic cloves into a paste against a cutting board using a fork or the flat of your knife. Stir the paste back into the soup.\n4 Season and serve: Stir the lemon juice into to the soup, and taste. The soup should taste rich, barely salty, and with just a hint of lemon. Add more salt or lemon juice as needed until it tastes good to you.\nDivide among bowls and sprinkle with some parsley for serving.\nLeftovers will keep for about a week refrigerated, or up to 3 months frozen.",
             self.harvester_class.instructions(),
         )