From: Ian Macdonald Date: 2004-03-16T17:36:56+09:00 Subject: Re: 1.6 to 1.8 problem? On Tue 16 Mar 2004 at 12:20:47 +0900, bob wrote: > I'm trying to run this ruby script from a magazine, so there are no typoes, > etc. Here's the error I get... > > D:\>ruby test.rb > test.rb:29:in `get_rank_for': Couldn't find sales rank in page > (RuntimeError) > from test.rb:61:in `value' > from test.rb:61 > from test.rb:61:in `collect' > from test.rb:61 > > ------------------------------------------- > and here's the code > ------------------------------------------- > #!/usr/bin/eval ruby -w > require 'net/http' > require 'uri' > > URLS = [ > ["www.amazon.com", "/exec/obidos/ASIN/020161622X/o" ], > ["www.amazon.com", "/exec/obidos/ASIN/0201710897" ], > ["www.amazon.co.jp", "/exec/obidos/ASIN/0201710897" ], > ["www.amazon.co.jp", "/exec/obidos/ASIN/4894714531" ], > ["www.amazon.co.jp", "/exec/obidos/ASIN/4894712741" ] > ] You may care to try the Ruby/Amazon library. It uses Amazon's XML over HTTP (REST) interface to query the Amazon Web Services (AWS) API. Using that, your code becomes quite simple: [ianmacd@sagan]$ irb --simple-prompt ~/src/ruby-amazon-0.7.5/lib >> require 'amazon/search' => true >> include Amazon::Search => Object >> req = Request.new => #"calibanorg-20", "locale"=>"us", "dev_token"=>"xxxxxxxxxxxxxx", "password"=>"mitja", "email"=>"ian@caliban.org"}, @token="xxxxxxxxxxxxxx", @user_agent="Ruby/Amazon 0.7.5", @conn=#> >> puts req.asin_search('020161622X').products[0].sales_rank 6921 => nil >> puts req.asin_search('0201710897').products[0].sales_rank 55377 => nil It also works for other locales. Its RAA page is here: http://raa.ruby-lang.org/list.rhtml?name=ruby-amazon Ian -- Ian Macdonald | America has been discovered before, but it System Administrator | has always been hushed up. -- Oscar Wilde ian@caliban.org | http://www.caliban.org | |