Skip to content

Commit

Permalink
Merge pull request #17 from jadkins89/addImageUrl
Browse files Browse the repository at this point in the history
Adding images to scrapes
  • Loading branch information
jadkins89 authored Apr 11, 2020
2 parents 4701ac3 + 06805fe commit b9c64ac
Show file tree
Hide file tree
Showing 61 changed files with 193 additions and 86 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ Depending on the recipe, certain fields may be left blank. All fields are repres
ingredients: [],
instructions: [],
servings: "",
image: "",
time: {
prep: "",
cook: "",
Expand Down
10 changes: 6 additions & 4 deletions helpers/puppeteerFetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@ const puppeteerFetch = async url => {
let html = await page.content();
try {
await browser.close();
} catch (error) {} // avoid websocket error if browser already closed
return html;
} finally {
return html;
} // avoid websocket error if browser already closed
} else {
try {
await browser.close();
} catch (error) {}
return Promise.reject(response._status);
} finally {
return Promise.reject(response._status);
}
}
};

Expand Down
1 change: 1 addition & 0 deletions helpers/recipe-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ function Recipe() {
total: ""
};
this.servings = "";
this.image = "";
}

module.exports = Recipe;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recipe-scraper",
"version": "1.14.1",
"version": "1.15.0",
"description": "A JS package for scraping recipes from the web.",
"author": "Justin Adkins <[email protected]>",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions scrapers/101cookbooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const oneHundredAndOne = url => {
const $ = cheerio.load(html);
const body = $(".wprm-recipe-container");

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = body.children("h2").text();

$(".wprm-recipe-ingredient").each((i, el) => {
Expand Down
3 changes: 3 additions & 0 deletions scrapers/allrecipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const allRecipes = url => {
};

const newAllRecipes = ($, Recipe) => {
Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = Recipe.name.replace(/\s\s+/g, "");

$(".recipe-meta-item").each((i, el) => {
Expand Down Expand Up @@ -76,6 +77,8 @@ const newAllRecipes = ($, Recipe) => {
};

const oldAllRecipes = ($, Recipe) => {
Recipe.image = $("meta[property='og:image']").attr("content");

$("#polaris-app label").each((i, el) => {
const item = $(el)
.text()
Expand Down
1 change: 1 addition & 0 deletions scrapers/ambitiouskitchen.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const ambitiousKitchen = url => {
const Recipe = new RecipeSchema();
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".wprm-recipe-name").text();

$(".wprm-recipe-ingredient").each((i, el) => {
Expand Down
1 change: 1 addition & 0 deletions scrapers/bbc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bbc = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".content-title__text").text();

$(".recipe-ingredients__list-item").each((i, el) => {
Expand Down
1 change: 1 addition & 0 deletions scrapers/bbcgoodfood.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bbcGoodFood = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-header__title").text();

$(".ingredients-list__item").each((i, el) => {
Expand Down
1 change: 1 addition & 0 deletions scrapers/bonappetit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const bonAppetit = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $("a.top-anchor").text();

$(".ingredients")
Expand Down
1 change: 1 addition & 0 deletions scrapers/budgetbytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const budgetBytes = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".wprm-recipe-name").text();

$(".wprm-recipe-ingredient-notes").remove();
Expand Down
1 change: 1 addition & 0 deletions scrapers/closetcooking.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const closetCooking = url => {
const Recipe = new RecipeSchema();
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe_title").text();

$(".ingredients")
Expand Down
1 change: 1 addition & 0 deletions scrapers/cookieandkate.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const cookieAndKate = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".tasty-recipes")
.children("h2")
.text();
Expand Down
1 change: 1 addition & 0 deletions scrapers/copykat.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const copykat = url => {
var Recipe = new RecipeSchema();
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(
$(".wprm-recipe-container").find(".wprm-recipe-name")
).text();
Expand Down
1 change: 1 addition & 0 deletions scrapers/damndelicious.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const damnDelicious = url => {

let titleDiv = $(".recipe-title");

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(titleDiv)
.children("h2")
.text();
Expand Down
1 change: 1 addition & 0 deletions scrapers/eatingwell.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const eatingWell = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".main-header")
.find(".headline")
.text()
Expand Down
1 change: 1 addition & 0 deletions scrapers/epicurious.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const epicurious = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $("h1[itemprop=name]")
.text()
.trim();
Expand Down
1 change: 1 addition & 0 deletions scrapers/finecooking.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const fineCooking = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe__title").text();

$(".recipe__nutrition").remove();
Expand Down
1 change: 1 addition & 0 deletions scrapers/food.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const food = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[name='og:image']").attr("content");
Recipe.name = $(".recipe-title").text();

$(".recipe-ingredients__item").each((i, el) => {
Expand Down
1 change: 1 addition & 0 deletions scrapers/foodandwine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const foodAndWine = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $("h1.headline").text();

$(".ingredients")
Expand Down
2 changes: 2 additions & 0 deletions scrapers/foodnetwork.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ const foodNetwork = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".o-AssetTitle__a-HeadlineText")
.first()
.text();

$(".o-Ingredients__a-Ingredient, .o-Ingredients__a-SubHeadline").each(
(i, el) => {
const item = $(el)
Expand Down
1 change: 1 addition & 0 deletions scrapers/gimmesomeoven.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const gimmeSomeOven = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".tasty-recipes-header-content")
.children("h2")
.first()
Expand Down
1 change: 1 addition & 0 deletions scrapers/kitchenstories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const kitchenStories = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-title").text();

$(".ingredients")
Expand Down
1 change: 1 addition & 0 deletions scrapers/myrecipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const myRecipes = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $("h1.headline")
.text()
.trim();
Expand Down
1 change: 1 addition & 0 deletions scrapers/seriouseats.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const seriousEats = url => {
};

const regularRecipe = ($, Recipe) => {
Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-title")
.text()
.replace(/\s\s+/g, "");
Expand Down
1 change: 1 addition & 0 deletions scrapers/simplyrecipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const simplyRecipes = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-callout")
.children("h2")
.text();
Expand Down
2 changes: 2 additions & 0 deletions scrapers/smittenkitchen.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const oldSmitten = ($, Recipe) => {
let servingWords = ["Yield", "Serve", "Servings"];
let servingsRegex = new RegExp(servingWords.join("|"), "i");

Recipe.image = $("meta[property='og:image']").attr("content");
body.each((i, el) => {
if (i === 0) {
Recipe.name = $(el)
Expand Down Expand Up @@ -84,6 +85,7 @@ const oldSmitten = ($, Recipe) => {
};

const newSmitten = ($, Recipe) => {
Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".jetpack-recipe-title").text();

$(".jetpack-recipe-ingredients")
Expand Down
1 change: 1 addition & 0 deletions scrapers/thepioneerwoman.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const thePioneerWoman = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-title")
.first()
.text();
Expand Down
1 change: 1 addition & 0 deletions scrapers/therealfoodrds.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const theRealFoodRds = url => {
const Recipe = new RecipeSchema();
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".tasty-recipes-entry-header")
.children("h2")
.first()
Expand Down
1 change: 1 addition & 0 deletions scrapers/thespruceeats.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const theSpruceEats = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".heading__title").text();

$(".simple-list__item").each((i, el) => {
Expand Down
1 change: 1 addition & 0 deletions scrapers/whatsgabycooking.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const whatsGabyCooking = url => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-header").text();

$(".wprm-recipe-ingredient").each((i, el) => {
Expand Down
20 changes: 12 additions & 8 deletions scrapers/woolworths.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const request = require("request");
const cheerio = require("cheerio");

const RecipeSchema = require("../helpers/recipe-schema");

Expand All @@ -25,17 +26,20 @@ const woolworths = url => {
url: recipeJsonUrl,
json: true
},
(error, response, body) => {
if (!error && response.statusCode === 200 && body) {
Recipe.name = body.Title.trim();
Recipe.ingredients = body.Ingredients.map(i =>
(error, response, html) => {
if (!error && response.statusCode === 200 && html) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = html.Title.trim();
Recipe.ingredients = html.Ingredients.map(i =>
i.Description.trim()
);
Recipe.time.prep = body.PreparationDuration.toString();
Recipe.time.cook = body.CookingDuration.toString();
Recipe.servings = body.Servings.toString();
Recipe.time.prep = html.PreparationDuration.toString();
Recipe.time.cook = html.CookingDuration.toString();
Recipe.servings = html.Servings.toString();
Recipe.instructions = [];
body.Instructions.split("\r\n").map(step => {
html.Instructions.split("\r\n").map(step => {
if (instructionsIndexRe.test(step)) {
Recipe.instructions.push(
instructionsIndexRe.exec(step)[1].trim()
Expand Down
1 change: 1 addition & 0 deletions scrapers/yummly.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ const yummy = url => {
const Recipe = new RecipeSchema();
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = $(".recipe-title").text();

$(".IngredientLine").each((i, el) => {
Expand Down
3 changes: 2 additions & 1 deletion test/constants/101cookbooksConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module.exports = {
ready: "",
total: "15 mins"
},
servings: "8"
servings: "8",
image: "https://images.101cookbooks.com/coleslaw-recipe-h.jpg?w=680"
}
};
7 changes: 5 additions & 2 deletions test/constants/allRecipesConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ module.exports = {
ready: "25 m",
total: ""
},
servings: "6"
servings: "6",
image: "https://images.media-allrecipes.com/userphotos/560x315/2253389.jpg"
},
expectedRecipeNew: {
name: "Crispy and Tender Baked Chicken Thighs",
Expand Down Expand Up @@ -57,6 +58,8 @@ module.exports = {
ready: "",
total: "1 hr 10 mins"
},
servings: "8"
servings: "8",
image:
"https://imagesvc.meredithcorp.io/v3/mm/image?url=https%3A%2F%2Fimages.media-allrecipes.com%2Fuserphotos%2F1061355.jpg"
}
};
4 changes: 3 additions & 1 deletion test/constants/ambitiouskitchenConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ module.exports = {
ready: "",
total: "45 minutes"
},
servings: "6"
servings: "6",
image:
"https://www.ambitiouskitchen.com/wp-content/uploads/2018/07/Street-Corn-Pasta-Salad-4.jpg"
}
};
4 changes: 3 additions & 1 deletion test/constants/bbcConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ module.exports = {
ready: "",
total: ""
},
servings: "Serves 2"
servings: "Serves 2",
image:
"https://ichef.bbci.co.uk/food/ic/food_16x9_448/recipes/sausage_and_gnocchi_bake_80924_16x9.jpg"
}
};
4 changes: 3 additions & 1 deletion test/constants/bbcgoodfoodConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ module.exports = {
ready: "",
total: ""
},
servings: "Makes 12"
servings: "Makes 12",
image:
"https://www.bbcgoodfood.com/sites/default/files/recipe_images/recipe-image-legacy-id--856543_10.jpg"
}
};
4 changes: 3 additions & 1 deletion test/constants/bonappetitConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ module.exports = {
ready: "",
total: ""
},
servings: "4 servings"
servings: "4 servings",
image:
"https://assets.bonappetit.com/photos/5d4b5b3cecc81500091c6835/16:9/w_1200,c_limit/0919-Soba-Noodles.jpg"
}
};
Loading

0 comments on commit b9c64ac

Please sign in to comment.