Skip to content

Instantly share code, notes, and snippets.

@DemitryT
Created August 16, 2011 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DemitryT/1149909 to your computer and use it in GitHub Desktop.
Save DemitryT/1149909 to your computer and use it in GitHub Desktop.
Ruby program to scrape specific information of a web page
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