Created
March 24, 2009 10:53
-
-
Save alexyoung/84030 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
require 'rubygems' | |
require 'hpricot' | |
require 'open-uri' | |
require 'cgi' | |
class PlayScrape | |
URL = "http://www.play.com/Search.aspx?searchtype=allproducts&searchstring=%s&page=search&pa=search&go.x=0&go.y=0" | |
def initialize | |
end | |
def search(terms) | |
page = post sprintf URL, CGI.escape(terms) | |
doc = Hpricot.parse(page) | |
prices = (doc/".info h6") | |
titles = (doc/".info h5 a") | |
results = {} | |
titles.each_with_index { |title, index| results[title.inner_html] = prices[index].inner_text } | |
results | |
end | |
def post(url) | |
open(URI.parse(url)).read | |
end | |
end | |
play = PlayScrape.new | |
pp play.search('back to the future') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment