Skip to content

Instantly share code, notes, and snippets.

@Papillard
Created July 18, 2017 08:33
Show Gist options
  • Save Papillard/bb8b9df7a8609113c76646abd9d43ba1 to your computer and use it in GitHub Desktop.
Save Papillard/bb8b9df7a8609113c76646abd9d43ba1 to your computer and use it in GitHub Desktop.
Scraping recipes from Kitchen Stories
require 'open-uri'
require 'nokogiri'
# Let's scrape recipes from https://kitchenstories.io/en/search?search=strawberry
puts "What's ingredient do you want recipes for?"
ingredient = gets.chomp
url = "https://kitchenstories.io/en/search?search=#{ingredient}"
# Get the HTML file from the URL
html_file = open(url)
# Build a Nokogiri doc from the file
html_doc = Nokogiri::HTML(html_file)
# Search for a class in Nokogiri doc and iterate on results
html_doc.search(".tile-container").each do |recipe|
link = recipe.search(".tile-link").attribute("href").value
recipe_name = recipe.search(".search-tile-title").text
infos = recipe.search(".search-item-subtitle").text
description = recipe.search(".search-tile-description").text
puts link
puts recipe_name
puts infos
puts description
puts "*" * 50
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment