I want to pass an array of URLs returned by my first function into of my second function, however I am unsure of how to do this.
require 'open-uri'
require 'nokogiri'
require 'byebug'
def fetch_recipe_urls
base_url = 'https://cooking.nytimes.com'
easy_recipe_url = 'https://cooking.nytimes.com/search?q=easy'
easy_searchpage = Nokogiri::HTML(open(easy_recipe_url))
recipes = easy_searchpage.search('//article[@class="card recipe-card"]/@data-url')
recipes_url_array = recipes.map do |recipe|
uri = URI.parse(recipe.text)
uri.scheme = "http"
uri.host = "cooking.nytimes.com"
uri.query = nil
uri.to_s
end
end
def scraper(url)
html_file = open(url).read
html_doc = Nokogiri::HTML(html_file)
recipes = Array.new
recipe = {
title: html_doc.css('h1.recipe-title').text.strip,
time: html_doc.css('span.recipe-yield-value').text.split("servings")[1],
steps: html_doc.css('ol.recipe-steps').text.split.join(" "),
ingredients: html_doc.css('ul.recipe-ingredients').text.split.join(" ")
}
recipes << recipe
end