January 26, 2021
Hot Topics:

Mining Amazon.com Catalog Data with Ruby

  • By Jason Gilmore
  • Send Email »
  • More Articles »

Searching a Product Group

Suppose you want to create a service that tracks the historical sales rankings of Ubuntu-related books sold through Amazon. The Ruby script used to retrieve the latest sales rankings executes on a daily basis, and it automatically adds any new Ubuntu-related books that appear with the results of searches for books having the term "Ubuntu" in the title. To perform this task you can use Ruby/AWS' ItemSearch class, searching the Book category using the Title attribute:

#!/usr/bin/ruby -w require 'rubygems' require 'amazon/aws/search' include Amazon::AWS include Amazon::AWS::Search is = ItemSearch.new( 'Books', { 'Title' => 'Ubuntu' } ) rg = ResponseGroup.new( 'SalesRank' ) req = Request.new resp = req.search( is, rg ) items = resp.item_search_response.items.item items.each do |item| asin = item.asin sales_rank = item.sales_rank puts "#{asin}: #{sales_rank}" end

At the time of publication, this script produced the following results:

B003YL3OXM: 45853 0137081308: 49740 0137003889: 410902 B000SET66M: 64106 159327257X: 33498 0470604506: 180920 1430219998: 150251 0470485051: 82790 0307587886: 136259 0596527209: 140876

Of course, in a real world situation you would probably store the ASINs along with additional product information within a database, and then link to a ranking table that stores the historical sales ranks.


Amazon's Product Advertising API can be a bit overwhelming due to the sheer breadth and depth of product offerings and other information it exposes. However, libraries such as Ruby/AWS give you the ability to focus upon efficiently mining that product data rather than getting lost in a sea of irrelevant search results. If you're currently using Ruby/AWS or another API library to create interesting services, tell us about it in the comments! And as always, ping me with your questions on Twitter at @wjgilmore!

About the Author

Jason Gilmore is founder of the publishing and consulting firm WJGilmore.com. He is the author of several popular books "Easy PHP Websites with the Zend Framework", "Easy PayPal with PHP", and "Beginning PHP and MySQL, Fourth Edition". Follow him on Twitter at @wjgilmore.

Page 2 of 2

This article was originally published on October 6, 2010

Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date