enter image description hereI am building a scraper/parsing method, but the website I am using (https://www.bbcgoodfood.com/search?q=banana)to get the value from have many different informations using the same classes (they have no id, and are in the very same tag). In my case, I just need the preparation time, but it gives me other stuff i don’t need.
What I need: ” 1 hr 5 mins” (the prep time could be only minutes, so i need everything before the ‘mins’, including it)
What I get: “1 hr 5 minsEasy” (also I can’t say which word will come after “mins”, could be “hard” for example)
this is where im stuck:
require 'nokogiri'
require 'open-uri'
require_relative "recipe"
class Scraper
def initialize(ingredient)
@ingredient = ingredient
end
def call
html = URI.open("https://www.bbcgoodfood.com/search?q=#{@ingredient}").read
doc = Nokogiri::HTML(html, nil, "utf-8")
results = []
doc.search("article.card.text-align-left.card--horizontal.card--inline.card--with-borders").first(1).each do |element|
name = element.search("h2.heading-4").text.strip
description = element.search(".region-clamper.line-clamper__content").text.strip
prep_time = element.search(".terms-icons-list__text.d-flex.align-items-center").children.text.strip.split("Easy").first
#to be continued...
end
results
end
end