Created
October 14, 2014 04:53
-
-
Save sai43/70c84dc13b27a0311bd0 to your computer and use it in GitHub Desktop.
Nokogiri gem example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
items = Array.new | |
prices = Array.new | |
doc = Nokogiri::HTML(open("http://www.thinkgeek.com/caffeine/feature/desc/0/all")) | |
items = doc.xpath("//div/a/h4").collect {|node| node.text.strip} | |
prices = doc.xpath("//div[contains(@class,'product')]/p[not(@style)]/text()").collect {|node| node.text.strip} | |
prices.delete("") | |
items.zip(prices).each do |title,price,i| | |
puts title+"\t"+price | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment