require 'rubygems'
require 'scrapi'
require 'open-uri'
require 'nkf'
require 'pp'
$KCODE = 'u'
recipeScrape = Scraper.define do
process "a > img.sphoto", :thum => "@src"
process "span.recipe-ttl > a", :title => :text, :url =>"@href"
process "span.author", :author => :text
process "p.recipe_desc", :desc => :text
process "p.recipe_material", :material => :text
process "p.recipe_info", :info => :text
result :thum, :title, :url, :author, :desc, :material, :info
end
cpsScrape = Scraper.define do
process "div.recipe_box", "recipes[]" => recipeScrape
result :recipes
end
html = URI.parse('http://cookpad.com/search/?keyword=%E3%83%90%E3%83%AC%E3%83%B3%E3%82%BF%E3%82%A4%E3%83%B3&l=0')
output = cpsScrape.scrape(html, :parser_options => { :char_encoding=>'utf8' })
print NKF::nkf("-s", output.pretty_inspect)