Skip to content

Commit

Permalink
Merge pull request #34 from mattbloomfield/adding-3-new-sources
Browse files Browse the repository at this point in the history
adding melskitchencafe, tasteofhome, therecipecritic
  • Loading branch information
jadkins89 authored Jan 7, 2021
2 parents dba27dd + 1fb12f9 commit 241b994
Show file tree
Hide file tree
Showing 23 changed files with 755 additions and 11 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,11 @@ recipeScraper("some.recipe.url").then(recipe => {
- https://www.food.com/
- https://www.foodandwine.com/
- https://www.foodnetwork.com/
- https://gimmedelicious.com/
- http://www.gimmesomeoven.com/
- https://julieblanner.com/
- https://www.kitchenstories.com/
- https://www.melskitchencafe.com/
- https://www.minimalistbaker.com/
- https://www.myrecipes.com/
- https://www.nomnompaleo.com/
Expand All @@ -64,7 +67,9 @@ recipeScraper("some.recipe.url").then(recipe => {
- https://www.simplyrecipes.com/
- https://smittenkitchen.com/
- https://thepioneerwoman.com/
- https://www.tasteofhome.com/
- https://tastesbetterfromscratch.com/
- https://www.theblackpeppercorn.com/
- https://therealfoodrds.com/
- https://www.thespruceeats.com/
- https://whatsgabycooking.com/
Expand Down
74 changes: 74 additions & 0 deletions scrapers/gimmedelicious.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const request = require("request");
const cheerio = require("cheerio");

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

const gimmedelicious = url => {
const Recipe = new RecipeSchema();
return new Promise((resolve, reject) => {
if (!url.includes("gimmedelicious.com/")) {
reject(new Error("url provided must include 'gimmedelicious.com/'"));
} else {
request(url, (error, response, html) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.tags = (
$("meta[name='keywords']").attr("content") || ""
).split(",");
Recipe.name = $(".wprm-recipe-name")
.text()
.trim();

$(".wprm-recipe-ingredients > .wprm-recipe-ingredient").each(
(i, el) => {
Recipe.ingredients.push(
$(el)
.text()
.replace(//g, "")
);
}
);

$(".wprm-recipe-instruction-text").each((i, el) => {
Recipe.instructions.push(
$(el)
.remove("img")
.text()
.trim()
);
});

Recipe.time.prep =
$(".wprm-recipe-prep_time-minutes").text() +
" " +
$(".wprm-recipe-prep_timeunit-minutes").text();
Recipe.time.cook =
$(".wprm-recipe-cook_time-minutes").text() +
" " +
$(".wprm-recipe-cook_timeunit-minutes").text();
Recipe.time.total =
$(".wprm-recipe-total_time-minutes").text() +
" " +
$(".wprm-recipe-total_timeunit-minutes").text();
Recipe.servings = $(".wprm-recipe-servings").text();

if (
!Recipe.name ||
!Recipe.ingredients.length ||
!Recipe.instructions.length
) {
reject(new Error("No recipe found on page"));
} else {
resolve(Recipe);
}
} else {
reject(new Error("No recipe found on page"));
}
});
}
});
};

module.exports = gimmedelicious;
10 changes: 10 additions & 0 deletions scrapers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ const domains = {
food: require("./food"),
foodandwine: require("./foodandwine"),
foodnetwork: require("./foodnetwork"),
gimmedelicious: require("./gimmedelicious"),
gimmesomeoven: require("./gimmesomeoven"),
julieblanner: require("./julieblanner"),
kitchenstories: require("./kitchenstories"),
melskitchencafe: require("./melskitchencafe"),
minimalistbaker: require("./minimalistbaker"),
myrecipes: require("./myrecipes"),
nomnompaleo: require("./nomnompaleo"),
Expand All @@ -31,6 +34,9 @@ const domains = {
simplyrecipes: require("./simplyrecipes"),
smittenkitchen: require("./smittenkitchen"),
tastesbetterfromscratch: require("./tastesbetterfromscratch"),
tasteofhome: require("./tasteofhome"),
theblackpeppercorn: require("./theblackpeppercorn"),
therecipecritic: require("./therecipecritic"),
thepioneerwoman: require("./thepioneerwoman"),
therealfoodrds: require("./therealfoodrds"),
thespruceeats: require("./thespruceeats"),
Expand All @@ -55,4 +61,8 @@ const recipeScraper = url => {
});
};

recipeScraper(
"https://www.thespruceeats.com/grilled-squid-recipe-1808848"
).then(recipe => console.log(recipe));

module.exports = recipeScraper;
72 changes: 72 additions & 0 deletions scrapers/julieblanner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
const request = require("request");
const cheerio = require("cheerio");

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

const julieblanner = url => {
const Recipe = new RecipeSchema();
return new Promise((resolve, reject) => {
if (!url.includes("julieblanner.com/")) {
reject(new Error("url provided must include 'julieblanner.com/'"));
} else {
request(url, (error, response, html) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

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

$(".wprm-recipe-ingredients > .wprm-recipe-ingredient").each(
(i, el) => {
Recipe.ingredients.push(
$(el)
.text()
.replace(/(\s\s+|▢)/g, " ")
.trim()
);
}
);

$(".wprm-recipe-instruction-text").each((i, el) => {
Recipe.instructions.push(
$(el)
.remove("img")
.text()
.trim()
);
});

Recipe.time.prep = $(".wprm-recipe-prep-time-label")
.next()
.text();
Recipe.time.cook = $(".wprm-recipe-cook-time-label")
.next()
.text();
Recipe.time.inactive = $(".wprm-recipe-custom-time-label")
.next()
.text();
Recipe.time.total = $(".wprm-recipe-total-time-label")
.next()
.text();
Recipe.servings = $(".wprm-recipe-servings").text();

if (
!Recipe.name ||
!Recipe.ingredients.length ||
!Recipe.instructions.length
) {
reject(new Error("No recipe found on page"));
} else {
resolve(Recipe);
}
} else {
reject(new Error("No recipe found on page"));
}
});
}
});
};

module.exports = julieblanner;
64 changes: 64 additions & 0 deletions scrapers/melskitchencafe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
const request = require("request");
const cheerio = require("cheerio");

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

const melskitchencafe = url => {
const Recipe = new RecipeSchema();
return new Promise((resolve, reject) => {
if (!url.includes("melskitchencafe.com/")) {
reject(new Error("url provided must include 'melskitchencafe.com/'"));
} else {
request(url, (error, response, html) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

const textTrim = el => el.text().trim();

Recipe.image = $("meta[property='og:image']").attr("content");
Recipe.name = textTrim(
$(".wp-block-mv-recipe .mv-create-title-primary")
);

$("div.mv-create-ingredients ul li").each((i, el) => {
Recipe.ingredients.push(textTrim($(el)));
});

$("div.mv-create-instructions ol li").each((i, el) => {
Recipe.instructions.push(textTrim($(el)));
});

Recipe.time.prep = textTrim(
$(".mv-create-time-prep .mv-create-time-format")
);
Recipe.time.cook = textTrim(
$(".mv-create-time-active .mv-create-time-format")
);
Recipe.time.inactive = textTrim(
$(".mv-create-time-additional .mv-create-time-format")
);
Recipe.time.total = textTrim(
$(".mv-create-time-total .mv-create-time-format")
);
Recipe.servings = textTrim(
$(".mv-create-time-yield .mv-create-time-format")
);

if (
!Recipe.name ||
!Recipe.ingredients.length ||
!Recipe.instructions.length
) {
reject(new Error("No recipe found on page"));
} else {
resolve(Recipe);
}
} else {
reject(new Error("No recipe found on page"));
}
});
}
});
};

module.exports = melskitchencafe;
63 changes: 63 additions & 0 deletions scrapers/tasteofhome.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
const request = require("request");
const cheerio = require("cheerio");

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

const tasteofhome = url => {
const Recipe = new RecipeSchema();
return new Promise((resolve, reject) => {
if (!url.includes("tasteofhome.com/recipes/")) {
reject(new Error("url provided must include 'tasteofhome.com/recipes/'"));
} else {
request(url, (error, response, html) => {
if (!error && response.statusCode === 200) {
const $ = cheerio.load(html);

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

$("meta[property='article:tag']").each((i, el) => {
Recipe.tags.push($(el).attr("content"));
});

$(".recipe-ingredients__list li").each((i, el) => {
Recipe.ingredients.push($(el).text());
});

$(".recipe-directions__item").each((i, el) => {
Recipe.instructions.push(
$(el)
.text()
.trim()
);
});

let timeStr = $(".recipe-time-yield__label-prep")
.text()
.split(/Bake:/g);
Recipe.time.prep = timeStr[0].replace("Prep:", "").trim();
Recipe.time.cook = (timeStr[1] || "").trim();
Recipe.servings = $(".recipe-time-yield__label-servings")
.text()
.trim();

if (
!Recipe.name ||
!Recipe.ingredients.length ||
!Recipe.instructions.length
) {
reject(new Error("No recipe found on page"));
} else {
resolve(Recipe);
}
} else {
reject(new Error("No recipe found on page"));
}
});
}
});
};

module.exports = tasteofhome;
Loading

0 comments on commit 241b994

Please sign in to comment.