public
Last active

Ruby program to scrape specific information of a web page

  • Download Gist
mechanize.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
require 'rubygems'
require 'nokogiri'
require 'open-uri'
 
# Get a Nokogiri::HTML:Document for the page we’re interested in...
url = 'http://www.groupon.com/denver/deals/next-door-lounge'
 
doc = Nokogiri::HTML(open(url)) #do |config|
doc.at_css("ul#counter li.ended").text
# config.noerror
#end
 
# Search for nodes by css
doc.css('h2.control_title').each do |link|
puts "\n"
puts "Deal Title: " +link.content.to_s.strip
puts "\n"
end
 
doc.css('.merchant_info.control.clearfix .merchant_name').each do |link|
puts "Merchant name: " +link.content.to_s.strip
puts "\n"
end
 
doc.css('#price_tag_inner #amount').each do |link|
puts "Price: " +link.content
puts "\n"
end
 
doc.css('.clearfix #deal_discount').each do |link|
puts link.content.to_s.strip.gsub(/ /,'')
puts "\n"
end
 
doc.css('td.left span.number').each do |link|
puts "Deals bought: " +link.content
puts "\n"
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.