Skip to content

Instantly share code, notes, and snippets.

@alexyoung
Created March 24, 2009 10:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexyoung/84030 to your computer and use it in GitHub Desktop.
Save alexyoung/84030 to your computer and use it in GitHub Desktop.
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