javascript - scrap data using Nokogiri available in span tag -


how scrap name , price of product of page http://www.tradus.com/t-shirts-tees-reebok-puma-fifa-teesort/t/7682?type=polo+neck using nokogiri , how scrap product of category pagination there.following code getting price in html tags , 1 page.

require 'nokogiri' require 'open-uri'  url = "http://www.tradus.com/t-shirts-tees-reebok-puma-fifa-teesort/t/7682?  type=polo+neck" doc = nokogiri::html(open(url)) doc.css(".prodlisting-item").each |dv| product_name = dv.at_css('.prod-name').text unless dv.at_css(".prod-name").nil? product_price = dv.at_css('.price-info span span:nth-child(2)').to_s  puts product_name + product_price end 

following code resolved issue require 'nokogiri' require 'open-uri'  number=1 while true url="http://www.tradus.com/t-shirts-tees-reebok-puma-fifa-teesort/t/7682?  type=polo+neck&page=#{number}" doc = nokogiri::html(open(url)) products=doc.css(".prodlisting-item") break if products.size == 0 products.each |item| product_name = item.at_css('.prod-name').text unless item.at_css(".prod-name").nil? product_price = item.at_css('.price-info span span:nth-child(2)').text unless     item.at_css(".price-info span span:nth-child(2)").nil? puts product_name +"<==========>" +product_price end puts "page" +"#{number}" number += 1  end puts "exit of while loop"          

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -