Skip to content

Instantly share code, notes, and snippets.

@naoranger
Created August 9, 2012 02:51
Show Gist options
  • Select an option

  • Save naoranger/3300465 to your computer and use it in GitHub Desktop.

Select an option

Save naoranger/3300465 to your computer and use it in GitHub Desktop.
nokogiri sample kakaku
require 'nokogiri'
require 'open-uri'
keyword = "crucial+ssd"
page = open("http://kakaku.com/search_results/#{keyword}/?sort=priceb")
html = Nokogiri::HTML(page.read, nil, 'Shift_JIS')
puts html.xpath('//p[@class="itemnameN"]//a').text
puts html.xpath('//span[@class="yen"]//a').text
=begin
html.xpath('//div[@class="itemInfo"]').each do |item|
puts item.search('span[@class="numOr"]').first.content+"位"
# puts item.search("a[@class='title']").first.content
puts item.search('p[@class="itemnameN"]').first.content
puts item.search('span[@class="yen"]').first.content
# puts item.search('span[@class="yen"]').first.content.sub(/\s[~]\s/, '')
# puts item.search('span[@class="yen"]').first.content.gsub(/¥(\d+),(\d+).+/, '\1\2')
end
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment