Repository: hhursev/recipe-scrapers
Pull request #92 (2019-12-01 14:47:24)

Partial image change revert
Hey @hhursev - thanks for implementing the abstract `og:image` handling in the base scraper and cleaning up the scrapers!

A few of the classes had `image` methods that were targeting other HTML elements, and a good number of `allrecipes` pages stopped returning images after upgrading to `recipe-scrapers==5.2.1`, so this PR restores those methods, without touching the rest of the `og:image` cleanup.

hhursev: Argh .. Thanks 👍 👍  Didn't expect links from the sites to not have og:image on some of their links, while having it in others.

Thanks, merging and will bump version 🍺 (big one)

Patch:
diff --git a/recipe_scrapers/allrecipes.py b/recipe_scrapers/allrecipes.py
index 096b0268..8f9a7267 100644
--- a/recipe_scrapers/allrecipes.py
+++ b/recipe_scrapers/allrecipes.py
@@ -46,6 +46,17 @@ class AllRecipes(AbstractScraper):
                 {'class': 'recipe-adjust-servings__original-serving'}
             ).get_text())
 
+    def image(self):
+        image = self.soup.find(
+            'img',
+            {'class': 'rec-photo', 'src': True}
+        )
+        if image is None:
+            image = self.soup.find('div', {'class': 'lead-media'})
+            return image['data-src'] if image else None
+
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.findAll(
             'li',
diff --git a/recipe_scrapers/bbcfood.py b/recipe_scrapers/bbcfood.py
index 327be7d1..b7f655d5 100644
--- a/recipe_scrapers/bbcfood.py
+++ b/recipe_scrapers/bbcfood.py
@@ -30,6 +30,20 @@ class BBCFood(AbstractScraper):
             {'class': 'recipe-metadata__serving'})
         )
 
+    def image(self):
+        container = self.soup.find(
+            True,
+            {'class': 'recipe-media__image'}
+        )
+        if not container:
+            return None
+
+        image = container.parent.find(
+            'img',
+            {'src': True}
+        )
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.findAll(
             'li',
diff --git a/recipe_scrapers/bbcgoodfood.py b/recipe_scrapers/bbcgoodfood.py
index a13b712b..6b0d6883 100644
--- a/recipe_scrapers/bbcgoodfood.py
+++ b/recipe_scrapers/bbcgoodfood.py
@@ -30,6 +30,13 @@ class BBCGoodFood(AbstractScraper):
             {'class': 'recipe-details__text', 'itemprop': 'recipeYield'}
         ))
 
+    def image(self):
+        image = self.soup.find(
+            'img',
+            {'itemprop': 'image', 'src': True}
+        )
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.findAll(
             'li',
diff --git a/recipe_scrapers/epicurious.py b/recipe_scrapers/epicurious.py
index 514012c3..6137c4cd 100644
--- a/recipe_scrapers/epicurious.py
+++ b/recipe_scrapers/epicurious.py
@@ -23,6 +23,13 @@ class Epicurious(AbstractScraper):
             {'itemprop': 'recipeYield'}
         ))
 
+    def image(self):
+        image = self.soup.find(
+            'img',
+            {'class': 'photo', 'srcset': True}
+        )
+        return image['srcset'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.findAll(
             'li',
diff --git a/recipe_scrapers/jamieoliver.py b/recipe_scrapers/jamieoliver.py
index 4196aa50..ef028bda 100644
--- a/recipe_scrapers/jamieoliver.py
+++ b/recipe_scrapers/jamieoliver.py
@@ -23,6 +23,20 @@ class JamieOliver(AbstractScraper):
             {'class': 'recipe-detail serves'})
         )
 
+    def image(self):
+        container = self.soup.find(
+            'div',
+            {'class': 'recipe-header-left'}
+        )
+        if not container:
+            return None
+
+        image = container.find(
+            'img',
+            {'src': True}
+        )
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.find(
             'ul',
diff --git a/recipe_scrapers/steamykitchen.py b/recipe_scrapers/steamykitchen.py
index 8775dee2..6112a2bd 100644
--- a/recipe_scrapers/steamykitchen.py
+++ b/recipe_scrapers/steamykitchen.py
@@ -23,6 +23,13 @@ class SteamyKitchen(AbstractScraper):
     def yields(self):
         return get_yields(self.soup.find('span', itemprop='recipeYield'))
 
+    def image(self):
+        image = self.soup.find(
+            'img',
+            {'itemprop': 'image', 'src': True}
+        )
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.findAll(
             'span',
diff --git a/recipe_scrapers/tastykitchen.py b/recipe_scrapers/tastykitchen.py
index 34ce1079..643332bd 100644
--- a/recipe_scrapers/tastykitchen.py
+++ b/recipe_scrapers/tastykitchen.py
@@ -33,6 +33,13 @@ class TastyKitchen(AbstractScraper):
             {'itemprop': 'yield'})
         )
 
+    def image(self):
+        image =  self.soup.find(
+            'img',
+            {'class': 'the_recipe_image', 'src': True}
+        )
+        return image['src'] if image else None
+
     def ingredients(self):
         ingredients = self.soup.find(
             'ul',
diff --git a/recipe_scrapers/twopeasandtheirpod.py b/recipe_scrapers/twopeasandtheirpod.py
index 0f47aa2b..8e4c7317 100644
--- a/recipe_scrapers/twopeasandtheirpod.py
+++ b/recipe_scrapers/twopeasandtheirpod.py
@@ -53,3 +53,11 @@ class TwoPeasAndTheirPod(AbstractScraper):
             normalize_string(instruction.get_text())
             for instruction in instructions
         ])
+
+    def image(self):
+        image = self.soup.find(
+            'div',
+            {'class': 'wprm-recipe-image'}
+        ).find('img')
+
+        return image['src'] if image else None


Test patch:
diff --git a/recipe_scrapers/tests/test_allrecipes_fallback_format.py b/recipe_scrapers/tests/test_allrecipes_fallback_format.py
index faf2b97c..4f548384 100644
--- a/recipe_scrapers/tests/test_allrecipes_fallback_format.py
+++ b/recipe_scrapers/tests/test_allrecipes_fallback_format.py
@@ -37,7 +37,7 @@ class TestAllRecipesFallbackFormatScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'https://images.media-allrecipes.com/userphotos/560x315/4488475.jpg',
+            'https://images.media-allrecipes.com/userphotos/4488475.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_bbcfood.py b/recipe_scrapers/tests/test_bbcfood.py
index c0c4e390..801e70b1 100644
--- a/recipe_scrapers/tests/test_bbcfood.py
+++ b/recipe_scrapers/tests/test_bbcfood.py
@@ -46,7 +46,7 @@ class TestBBCFoodScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'https://ichef.bbci.co.uk/food/ic/food_16x9_448/recipes/baileysandchocolatec_72293_16x9.jpg',
+            'https://ichef.bbci.co.uk/food/ic/food_16x9_608/recipes/baileysandchocolatec_72293_16x9.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_bbcgoodfood.py b/recipe_scrapers/tests/test_bbcgoodfood.py
index 8b198e73..c0e8021e 100644
--- a/recipe_scrapers/tests/test_bbcgoodfood.py
+++ b/recipe_scrapers/tests/test_bbcgoodfood.py
@@ -40,7 +40,7 @@ class TestBBCGoodFoodScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'https://www.bbcgoodfood.com/sites/default/files/recipe_images/recipe-image-legacy-id--405483_12.jpg',
+            '//www.bbcgoodfood.com/sites/default/files/styles/recipe/public/recipe_images/recipe-image-legacy-id--405483_12.jpg?itok=y0VkmKq3',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_epicurious.py b/recipe_scrapers/tests/test_epicurious.py
index f46b6f90..e38585d9 100644
--- a/recipe_scrapers/tests/test_epicurious.py
+++ b/recipe_scrapers/tests/test_epicurious.py
@@ -40,7 +40,7 @@ class TestEpicurious(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'https://assets.epicurious.com/photos/568194b8fb9544f72b678fd4/2:1/w_1260%2Ch_630/Ramen-Noodle-Bowl-With-Escarole.jpg',
+            'https://assets.epicurious.com/photos/568194b8fb9544f72b678fd4/6:4/w_274%2Ch_169/Ramen-Noodle-Bowl-With-Escarole.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_jamieoliver.py b/recipe_scrapers/tests/test_jamieoliver.py
index 0c640976..e93ca69e 100644
--- a/recipe_scrapers/tests/test_jamieoliver.py
+++ b/recipe_scrapers/tests/test_jamieoliver.py
@@ -40,7 +40,7 @@ class TestJamieOliverScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'http://cdn.jamieoliver.com/_beta/images/jamie_fb-share_3.jpg',
+            'jamieoliver_files/88_1_1441269331.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_steamykitchen.py b/recipe_scrapers/tests/test_steamykitchen.py
index 2559c23b..d2c87a7d 100644
--- a/recipe_scrapers/tests/test_steamykitchen.py
+++ b/recipe_scrapers/tests/test_steamykitchen.py
@@ -40,7 +40,7 @@ class TestSteamyKitchenScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'https://steamykitchen.com/wp-content/uploads/2012/11/pork-paprikash-recipe-featured-9514.jpg',
+            'https://steamykitchen.com/wp-content/uploads/2012/11/pork-paprikash-recipe-featured-9514-180x220.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_tastykitchen.py b/recipe_scrapers/tests/test_tastykitchen.py
index 7a2d90cd..b963c1d8 100644
--- a/recipe_scrapers/tests/test_tastykitchen.py
+++ b/recipe_scrapers/tests/test_tastykitchen.py
@@ -40,7 +40,7 @@ class TestTastyKitchenScraper(unittest.TestCase):
 
     def test_image(self):
         self.assertEqual(
-            'http://tastykitchen.com/recipes/wp-content/uploads/sites/2/2015/08/Cheddar-and-Garlic-Scape-Biscuits-by-Superman-Cooks-410x273.jpg',
+            'tasty_kitchen_files/Cheddar-and-Garlic-Scape-Biscuits-by-Superman-Cooks-410x273.jpg',
             self.harvester_class.image()
         )
 
diff --git a/recipe_scrapers/tests/test_twopeasandtheirpod.py b/recipe_scrapers/tests/test_twopeasandtheirpod.py
index b7941ea5..6ad0c1c5 100644
--- a/recipe_scrapers/tests/test_twopeasandtheirpod.py
+++ b/recipe_scrapers/tests/test_twopeasandtheirpod.py
@@ -71,6 +71,6 @@ class TestTwoPeasAndTheirPodScraper(unittest.TestCase):
 
     def test_image(self):
         return self.assertEqual(
-            'https://www.twopeasandtheirpod.com/wp-content/uploads/2017/03/Baked-Chicken-Taquitos-1.jpg',
+            'https://www.twopeasandtheirpod.com/wp-content/uploads/2017/03/Baked-Chicken-Taquitos-1-220x220.jpg',
             self.harvester_class.image()
         )