require "nokogiri" require "open-uri" require "pry" class Scraper def fetch_frontpage(frontpage) raw = URI.open(frontpage) parsed = Nokogiri::HTML(raw) target = parsed.css("a.titlelink") links = target.map { |link| link = link.attribute("href").value } create_posts(links) end def create_posts(links) links.map do |post| puts post raw = URI.open(post) parsed = Nokogiri::HTML(raw) # binding.pry # unless something? # Exit and move on to next item in `links` # end puts end end end # Start the script scrape = Scraper.new scrape.fetch_frontpage("https://news.ycombinator.com")