Created
December 9, 2009 23:04
-
-
Save shayne/252939 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 'nokogiri' | |
require 'open-uri' | |
require 'pp' | |
products = [] | |
macs = %w{imac macbook macbook_pro macbook_air mac_mini mac_pro xserve displays mac_accessories} | |
macs.each do |mac| | |
doc = Nokogiri::HTML(open("http://store.apple.com/us/browse/home/specialdeals/mac/#{mac}")) | |
doc.search('tr').each do |p| | |
products << { | |
:name => p.at('.specs a').text.strip, | |
:price => p.at('.current_price').text.strip, | |
:specs => p.at('.specs').text.strip.split(/\s{2,}|\n+/)[1..-1] | |
} | |
end | |
end | |
pp products | |
__END__ | |
[{:price=>"$849.00", | |
:specs=> | |
["20-inch glossy widescreen display", | |
"2GB memory", | |
"320GB hard drive", | |
"8x SuperDrive (DVD±R DL/DVD±RW/CD-RW)", | |
"NVIDIA GeForce 9400M with 256MB memory", | |
"Built-in iSight camera"], | |
:name=>"Refurbished iMac 20-inch 2.66GHz Intel Core 2 Duo"}, | |
{:price=>"$1,099.00", | |
:specs=> | |
["24-inch glossy widescreen display", | |
"4GB memory", | |
"640GB hard drive", | |
"8x SuperDrive (DVD±R DL/DVD±RW/CD-RW)", | |
"NVIDIA GeForce 9400M with 256MB memory", | |
"Built-in iSight camera"], | |
:name=>"Refurbished iMac 24-inch 2.66GHz Intel Core 2 Duo"}, | |
{:price=>"$1,279.00", | |
:specs=> | |
["24-inch glossy widescreen display", | |
"4GB memory", | |
"640GB hard drive", | |
"8x SuperDrive (DVD±R DL/DVD±RW/CD-RW)", | |
"NVIDIA GeForce GT 120 with 256MB memory", | |
"Built-in iSight camera"], | |
:name=>"Refurbished iMac 24-inch 2.93GHz Intel Core 2 Duo"}, | |
{:price=>"$1,349.00", | |
:specs=> | |
["24-inch glossy widescreen display", | |
"4GB memory", | |
"1TB hard drive", | |
"8x SuperDrive (DVD±R DL/DVD±RW/CD-RW)", | |
"NVIDIA GeForce GT 130 with 512MB memory", | |
"Built-in iSight camera"], | |
:name=>"Refurbished iMac 24-inch 3.06GHz Intel Core 2 Duo"}, | |
{:price=>"$749.00", | |
:specs=> | |
["13.3-inch glossy widescreen display", | |
"2GB memory", | |
"160GB hard drive", | |
"NVIDIA GeForce 9400M graphics", | |
"Built-in iSight camera"], | |
:name=>"Refurbished MacBook 2.13GHz Intel Core 2 Duo - White"}, | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment