I'm trying to transition this bit of code from scrubyt to nokogiri, and am stuck trying to write my results to either a hash or xml. In scrubyt it looks like the following:
require 'rubygems'
require 'scrubyt'
result_data = Scrubyt::Extractor.define do
fetch "http://rads.stackoverflow.com/amzn/click/0061673730"
results "//div[@class='resultsset']" do
item "//tbody/tr" do
condition "//div[@class = 'Condition']"
price "//span[@class = 'price']"
shipping "//span[@class = 'price_shipping']"
end
end
end
@description = result_data.to_xml
return @description
end
With nokogiri I can parse out the information I want, but there doesn't seem to be a quick way to return items in a hash or xml document. Here's all I have in nokogiri.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.amazon.com/gp/offer-listing/0061673730'))
doc.css('div.condition, span.price, span.price_shipping ').each do |item|
puts item.content
end
How would one return item information to either xml or a hash?