Documentation ¶
Overview ¶
Package recipe is a Go library that scrapes recipes from websites.
The go-recipe default scraper looks for a `ld+json` encoded Schema Recipe on the target website and is able to retrieve most fields defined in the schema. However, some websites have incomplete Schema data or simply do not encode their recipe in such a format.
Therefore, custom scrapers exist that are used to scrape specific websites. These scrapers can make use of the default scraper so that custom scraping logic is only defined for fields that the default scraper could not find any data for.
The custom scrapers are registered in scrapers.go and are identified by host name, which represents the website that they are used for. When a client provides go-recipe with a link to scrape, the host name is extracted from the link and is used to find the corresponding custom scraper. The default scraper is used if no custom scraper is defined.
Example ¶
package main import "github.com/kkyr/go-recipe/pkg/recipe" func main() { url := "https://minimalistbaker.com/quick-pickled-jalapenos/" recipe, err := recipe.ScrapeURL(url) if err != nil { // handle err } ingredients, ok := recipe.Ingredients() instructions, ok := recipe.Instructions() // ... & more fields available }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Nutrition ¶
type Nutrition struct { // The number of calories. Calories float32 // The number of grams of carbohydrates. CarbohydrateGrams float32 // The number of milligrams of cholesterol. CholesterolMilligrams float32 // The number of grams of fat. FatGrams float32 // The number of grams of fiber. FiberGrams float32 // The number of grams of protein. ProteinGrams float32 // The number of grams of saturated fat. SaturatedFatGrams float32 // The serving size, in terms of the number of volume or mass. ServingSize string // The number of milligrams of sodium. SodiumMilligrams float32 // The number of grams of sugar. SugarGrams float32 // The number of grams of trans fat. TransFatGrams float32 // The number of grams of unsaturated fat. UnsaturatedFatGrams float32 }
Nutrition represents nutritional information about a recipe.
type Scraper ¶
type Scraper interface { // Author is the author of the recipe. Author() (string, bool) // Categories are the categories of the recipe, e.g. appetizer, entrée, etc. Categories() ([]string, bool) // CookTime is the time it takes to actually cook the dish. CookTime() (time.Duration, bool) // Cuisine is the cuisine of the recipe, e.g. mexican-inspired, french, etc. Cuisine() ([]string, bool) // Description is the description of the recipe. Description() (string, bool) // ImageURL is a URL to an image of the dish. ImageURL() (string, bool) // Ingredients are all the ingredients used in the recipe. Ingredients() ([]string, bool) // Instructions are all the steps in making the recipe. Instructions() ([]string, bool) // Language is the language used in the recipe expressed in IETF BCP 47 standard. Language() (string, bool) // Name is the name of the recipe. Name() (string, bool) // Nutrition is nutritional information about the dish. Nutrition() (Nutrition, bool) // PrepTime is the length of time it takes to prepare the items to be used in the instructions. PrepTime() (time.Duration, bool) // SuitableDiets indicates dietary restrictions or guidelines for which the recipe is suitable. SuitableDiets() ([]Diet, bool) // TotalTime is the total time required to perform the instructions (including the prep time). TotalTime() (time.Duration, bool) // Yields is the quantity that results from the recipe. Yields() (string, bool) }
Scraper is a type that is returns recipe information from an underlying data source.