Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Ruby program to scrape specific information of a web page

View mechanize.rb
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.