Skip to content

Instantly share code, notes, and snippets.

@sai43
Created October 14, 2014 04:53
Show Gist options
  • Save sai43/70c84dc13b27a0311bd0 to your computer and use it in GitHub Desktop.
Save sai43/70c84dc13b27a0311bd0 to your computer and use it in GitHub Desktop.
Nokogiri gem example
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