Industry guru Dave Taylor answers free tech support questions about a wide variety of business and technical topics, including blogging, Google AdSense, MySpace, Sony PSP, Apple iPod, Mp3 players, management, Linux, SEO, Mac OS X, Facebook, Twitter, LinkedIn and Microsoft Windows.

Can I keep track of my Amazon book rank with a script?

Dave, do you happen to have a script that will pull Amazon.com hourly sales rank data for 1 - N ASINs and save into either a CSV file or a database?

Dave's Answer:

This isn't too hard to create, because Amazon has nicely formed URLs which make identifying a specific page easy, and has well-formed HTML that makes it easy to pull out the specific information.

Let's have a look...

My book Wicked Cool Shell Scripts has an ASIN (Amazon Stock Identification Number) of 1593270127.

Based on that, we can create a URL that has the ASIN embedded within to obtain the page that has information on that particular book:

http://www.amazon.com/exec/obidos/
  tg/detail/-/asin/ref=nosim
Click on this link and you'll see, if you add the properly formatted ASIN it takes you to the information page.

That's half the work, right? Now the other half is to figure out how to extract the Amazon Ranking value, and that's surprisingly easy to do:

lynx -dump "$target" | grep -i "Amazon.com Sales Rank"
Where "target" is the URL shown earlier, with the appropriate ASIN. I run this snippet and here's what I see:
     * Amazon.com Sales Rank in [69]Books: #51,988
That's what we want, so all we have to do is cut everything out but the numeric value, and that's easily done by noting that there's a "#" prefacing the value and using cut to split the line at that point.

Here's the full sequence to extract one ranking for one ASIN:

#!/bin/sh

  asin=1593270127
target="http://www.amazon.com/exec/obidos/tg/detail/-/$asin/ref=nosim"

lynx -dump "$target" | grep -i "Amazon.com Sales Rank" | \
  cut -d# -f2
Run this, and you'll get the current sales rank.

To turn this into a script that loops through a file of ASINs should be straightforward, and to then save the output into a database or, say, comma separated values (CSV) file should be similarly easy.

I hope that gets you on the right track!



Help others find this article at Del.icio.us, Digg, Netscape, Reddit, and Simpy.

Subscribe!

Never miss another useful Q&A article again! Subscribe to AskDaveTaylor with Google Reader.

Comments

Even better, there's already a website that does this: www.rankforest.com. It tracks thousands of amazon sales ranks for products by the hour and lets you see pretty graphs and charts too.

Posted by: Brian Culler at June 5, 2006 9:50 AM

I would actually recommend that you use Amazon Web Services. It will allow you to retrieve an XML file with the information you want such as sales rank. This is quicker and you don't have to worry about Amazon changing the format of the page text so that this script would not longer work ...

Posted by: Andrew Krause at October 29, 2007 1:26 PM

I have a lot to say, but ...
Starbucks coffee cup I have a lot to say, and questions of my own for that matter, but most of all I'd like to say thank you for all your efforts on this Web site by buying you a chai!

I do have a comment, now that you mention it!









Remember personal info?


Please note that I will never send you any unsolicited commercial email. Ever.

While I'm at it, please note that by submitting a question or comment you're agreeing to my terms of service, which are: you relinquish any subsequent rights of ownership to your material by submitting it on this site.









Search
Find just the answers you seek from among our 1700+ free tech support articles by using our Lijit search engine.


Help!





Subscribe to
Ask Dave Taylor!

Add to Google Reader
Add to My Yahoo!
Subscribe in NewsGator Online

RDF   XML

Free Updates!
Sign up and get free weekly updates and special offers on books, seminars, workshops and more.


Recent Entries
Join the List!
Join my author info mailing list, where you'll learn about my upcoming books, speaking gigs, and more!


Book Links
© 2002 - 2008 by Dave Taylor. All Rights Reserved.

Note: This web site is for the purpose of disseminating information for educational purposes, free of charge, for the benefit of all visitors. We take great care to provide quality information. However, we do not guarantee, and accept no legal liability whatsoever arising from or connected to, the accuracy, reliability, currency or completeness of any material contained on this web site or on any linked site.

[whiteboard marker tray]