-
-
Save stan/289929 to your computer and use it in GitHub Desktop.
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
## solving Railscast #190 with "Scraper" | |
## http://github.com/mislav/scraper | |
## http://railscasts.com/episodes/190-screen-scraping-with-nokogiri | |
require 'rubygems' | |
require 'nokogiri' | |
require 'open-uri' | |
require 'scraper' | |
class Walmart < Scraper | |
element :title | |
elements '.item' => :items do | |
element '.prodLink' => :title | |
element '.PriceCompare .BodyS, .PriceXLBold' => :price, :with => lambda { |node| | |
node.inner_text[/\$[0-9\.]+/] | |
} | |
element 'a/@href' => :href | |
end | |
end | |
result = Walmart.parse open('http://www.walmart.com/search/search-ng.do?search_constraint=0&ic=48_0&search_query=batman&Find.x=0&Find.y=0&Find=Find') | |
puts result.title | |
result.items.each do |item| | |
puts "#{item.title} - #{item.price}\n #{item.href}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment