Skip to content

Instantly share code, notes, and snippets.

@albemuth
Created August 24, 2009 19:41
Show Gist options
  • Save albemuth/174099 to your computer and use it in GitHub Desktop.
Save albemuth/174099 to your computer and use it in GitHub Desktop.
vibram scrape
#!/usr/bin/ruby
require 'net/http'
require 'uri'
class Array
def map_to_hash
map { |e| yield e }.inject({}) { |carry, e| carry.merge! e }
end
end
my_size = 'M 40'
url = URI.parse('http://www.vibramfivefingers.com')
html = Net::HTTP.start(url.host, url.port) {|http|
http.get('/products/products_KSO_m.cfm')
}.body
#productsList[42] = new product(42, '146C', 'M,F', 41,30, 'grey-camo');
colors = html.grep( /new product/ ).
map{ |c| c.gsub(/.*\((.*)\).*/, "\\1").split(',') }.
map_to_hash{ |x| {x[0] => x[-1].chop}}
#productsList[42].sizes['M 40'] = 1;
res = html.grep( /sizes\['#{my_size}'\]/ ).
map{ |c| c.gsub(/.*\[(\d+)\].sizes\['#{my_size}'\] = ([01]);/, "\\1,#{"\\2"}").split(',') }.
find_all{ |x| x[1].chop == '1'}.
map{ |x| colors[x.first]}
print "==========================\n\n"
print "Colors: "
print res.join( ',' ).gsub( "'", '')
print "\n\n==========================\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment