Sha256: 8210de605679dcddbd76fa5c8d77de679b64aab0c81ccc3c00df20f25c9c5846
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
class TodaysTopDesserts::Scraper def self.scrape_desserts #returns an array of recipes with a name and url. page = Nokogiri::HTML(open("https://www.allrecipes.com/recipes/79/desserts/")) desserts = [] page.css("article.list-recipes")[0].css("li")[0..9].each do |dessert| desserts << { :name => dessert.css("img").attr("title").text, :url => dessert.css("a").attr("href").value } end desserts end def self.scrape_recipe(recipe_url) #returns a hash of recipe attributes page = Nokogiri::HTML(open(recipe_url)) recipe = {} recipe[:author] = page.css(".submitter__name").text.strip recipe[:description] = page.css(".submitter__description").text.strip recipe[:serving_size] = page.css("#metaRecipeServings").attr("content").value recipe[:prep_time] = page.css("time[itemprop='prepTime']").text.strip recipe[:cook_time] = page.css("time[itemprop='cookTime']").text.strip recipe[:ready_time] = page.css("time[itemprop='totalTime']").text.strip recipe[:calorie_count] = page.css(".calorie-count").text.strip recipe[:ingredients] = [] page.css("span[itemprop='ingredients']").each do |ingredient| recipe[:ingredients] << ingredient.text.strip end recipe[:instructions] = [] page.css("ol[itemprop='recipeInstructions'] span.recipe-directions__list--item").each do |instruction| recipe[:instructions] << instruction.text.strip end recipe end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
todays_top_desserts-0.1.0 | lib/todays_top_desserts/scraper.rb |