daily pastebin goal
62%
SHARE
TWEET

Page_scrap_nokogiri

shamshul2007 Sep 7th, 2013 34 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. require 'rubygems'
  2. require 'nokogiri'
  3. require 'mechanize'
  4. require 'open-uri'
  5.  
  6. url = "http://www.flipkart.com/mens-footwear/shoes/casual-shoes/pr?sid=osp,cil,nit,e1f"
  7. number=1
  8. doc = Nokogiri::HTML(open(url))
  9. #puts doc.at_css("title").text
  10.  
  11. doc.css(".gu4,.browse-product").each do |item|
  12.  
  13.   title = item.at_css(".fk-display-block,.title").text
  14.   #puts title.to_s.strip
  15.   title=title.to_s.strip
  16.    
  17.   #puts "================="
  18.   price = item.at_css(".pu-final").text unless item.at_css(".pu-final").nil?
  19.   #puts price.to_s.strip
  20.   price=price.to_s.strip
  21. puts number
  22.   puts "#{title} - #{price}"
  23.   link=item.at_css(".fk-display-block")[:href] unless item.at_css(".fk-display-block").nil?
  24.   puts "www.flipkart.com"+"#{link}"
  25.   image=item.at_css("div a img")[:'data-src'] unless item.at_css("div a img").nil?
  26.   puts image
  27.  
  28.   puts "========================"
  29. number=number+1
  30. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top