Searching for books with the Amazon Product Advertising API - Python

tl;dr : I am using the Amazon Product Advertising API with Python. How can I do a keyword search for a book and get XML results that contain TITLE, ISBN, and PRICE for each entry?

Verbose version:

I am working in Python on a web site that allows the user to search for textbooks from different sites such as eBay and Amazon. Basically, I need to obtain simple information such as titles, ISBNS, and prices for each item from a set of search results from one of those sites. Then, I can store and format that information as needed in my application (e.g, displaying HTML).

In eBay's case, getting the info I needed wasn't too hard. I used urllib2 to make a request based on a sample I found. All I needed was a special security key to add to the URL:

def ebaySearch(keywords): #keywords is a list of strings, e.g. ['moby', 'dick'] 

  #findItemsAdvanced allows category filter -- 267 is books 
  #Of course, I replaced my security appname in the example below 

  url = "[MY-APPNAME]&RESPONSE-DATA-FORMAT=XML&REST-PAYLOAD&categoryId=267&keywords="

  #Complete the url...  
  numKeywords = len(keywords)
  for k in range(0, numKeywords-1):
    url += keywords[k]
    url += "%20"  

  #There should not be %20 after last keyword
  url += keywords[numKeywords-1] 

  request = urllib2.Request(url) 
  response = urllib2.urlopen(request)  #file like thing (due to library conversion)

  xml_response =

...Then I parsed this with minidom.

In Amazon's case, it doesn't seem to be so easy. I thought I would start out by just looking for an easy wrapper. But their developer site doesn't seem to provide a python wrapper for what I am interested in (the Product Advertising API). One that I have tried, python-amazon-product-api 0.2.5 from, has been giving me some installation issues that may not be worth the time to look into (but maybe I'm just exasperated..). I also looked around and found pyaws and pyecs, but these seem to use deprecated authentication mechanisms.

I then figured I would just try to construct the URLs from scratch as I did for eBay. But Amazon requires a time stamp in the URLs, which I suppose I could programatically construct (perhaps something like these folks, who go the whole 9 yards with the signature:

Even if that worked (which I doubt will happen, given the amount of frustration the logistics have given so far), the bottom line is that I want name, price, and ISBN for the books that I search for. I was able to generate a sample URL with the tutorial on the API website, and then see the XML result, which indeed contained titles and ISBNs. But no prices! Gah! After some desperate Google searching, a slight modification to the URL (adding &ResponseGroup=Offers and &MerchantID=All) did the trick, but then there were no titles. (I guess yet another question I would have, then, is where can I find an index of the possible ResponseGroup parameters?)

Overall, as you can see, I really just don't have a solid methodology for this. Is the construct-a-url approach a decent way to go, or will it be more trouble than it is worth? Perhaps the tl;dr at the top is a better representation of the overall question.


Another way could be amazon-simple-product-api:

from amazon.api import AmazonAPI
results = = "book name", SearchIndex = "Books")
for item in results:
    print item.title, item.isbn, item.price_and_currency

To install, just clone from github and run

sudo python install

Hope this helps!

Need Your Help

How can I disable/hide edit button in gridview control of gridview hide edit

I have a gridview control in which there are two command buttons (linkButton), one is "select" and the other is "edit", now I have a session variable named as department and it contains values like

How I get the html all source?

android string inputstream bufferedreader

I mean that I use below code to get html source from url. But it does not contain all source.Buffersize is problem or string size problem?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.