recipe-scraper
A NodeJS package for scraping recipes from the web.
Installation
yarn install react-native-recipe-scraper
Usage
const recipeScraper = require("react-native-recipe-scraper");
async function someAsyncFunc() {
...
let recipe = await recipeScraper("some.recipe.url");
...
}
recipeScraper("some.recipe.url").then(recipe => {
}).catch(error => {
});
Supported Websites
And many more! the list above is old fashioned scraping, but for all those websites who have google recipe ld json included, it will also work.
Recipe Object
Depending on the recipe, certain fields may be left blank. All fields are represented as strings or arrays of strings. The name, ingredients, and instructions properties are required for schema validation.
{
name: "",
ingredients: [],
instructions: [],
tags: [],
servings: "",
image: "",
time: {
prep: "",
cook: "",
active: "",
inactive: "",
ready: "",
total: ""
}
}
Error Handling
If a recipe is not found on the given url, the basic page info will be returned: title, image & description.
If the url provided is invalid and a domain is unable to be parsed, an error message will be returned.
recipeScraper("keyboard kitty").catch((error) => {
console.log(error.message);
});
If a page does not exist or some other 400+ error occurs when fetching, an error message will be returned.
recipeScraper("some.nonexistent.page").catch((error) => {
console.log(error.message);
});
If a supported url does not contain the proper sub-url to be a valid recipe, an error message will be returned including the sub-url required.
recipeScraper("some.improper.url").catch((error) => {
console.log(error.message);
});
Bugs
With web scraping comes a reliance on the website being used not changing format. If this occurs we need to update our scrape. Please reach out if you are experiencing an issue.
Contributing
I welcome pull requests that keep the scrapes up to date or add new ones. I'm doing my best to keep this package maintained and with your help this goal is much more achievable. Please add testing if you add a scrape. Thank you 😁