Created
August 16, 2011 19:20
-
-
Save DemitryT/1149909 to your computer and use it in GitHub Desktop.
Ruby program to scrape specific information of a web page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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