Getting, visiting and limiting the number of links using Nokogiri and Mechanize?
问题 I am trying to scrape the five latest stories from CNN.com and retrieve their links along with the first paragraph of each story. I have this simple script: url = "http://edition.cnn.com/?refresh=1" agent = Mechanize.new agent.get("http://edition.cnn.com/?refresh=1").search("//div[@id='cnn_maintt2bul']/div/div/ul/li[count(*)=3]/a").each do |headline| article = headline.text link = URI.join(url, headline[:href]).to_s page = headline.click(link) paragraph1 = page.at_css(".adtag15090+ p").text