Book Search with Amazon Product Advertising APIs - Python

tl; dr: I am using the Amazon product advertising API with Python. How can I search for keywords for a book and get XML results containing TITLE, ISBN, and PRICE for each record?

Extended version:

I work in Python on a website that allows the user to search for tutorials from different sites such as eBay and Amazon. Basically, I need to get simple information such as headers, ISBNS, and prices for each item from a set of search results from one of these sites. Then I can store and format this information as necessary in my application (for example, display HTML).

In the eBay case, getting the information I needed was not too difficult. I used urllib2 to make a request based on the sample I found. All I need is a special security key to add to the url:

 def ebaySearch(keywords): #keywords is a list of strings, eg ['moby', 'dick'] #findItemsAdvanced allows category filter -- 267 is books #Of course, I replaced my security appname in the example below url = "http://svcs.ebay.com/services/search/FindingService/v1?OPERATION-NAME=findItemsAdvanced&SERVICE-NAME=FindingService&SERVICE-VERSION=1.0.0&SECURITY-APPNAME=[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 = response.read() ... 

... Then I made it out with the mini-house.

In the case of Amazon, this does not look so simple. I thought I would start by just finding lightweight packaging. But their developer's site doesn't seem to provide a python shell for what interests me (product advertising API). The one I tried, python-amazon-product-api 0.2.5 from https://pypi.python.org/pypi/python-amazon-product-api/ , gave me some installation problems that may not be worth the time take a look at (but maybe I'm just pissed off ..). I also looked around and found pyaws and pyecs, but they seem to use legacy authentication mechanisms.

Then I decided that I would just try to create URLs from scratch, as was the case with eBay. But Amazon requires a timestamp in the URLs, which I suppose I could build programmatically (maybe something like these people who go the whole 9 yards with a signature: https://forums.aws.amazon.com/ thread.jspa? threadID = 10048 ).

Even if it worked (I doubt it will happen, given the number of disappointments provided by logistics so far), the bottom line is that I want a name, price, and ISBN for the books I'm looking for. I was able to create a sample tutorial URL on the API website, and then see the XML result, which does indeed contain headers and ISBNs. But no price! G! After some desperate Google search, a minor URL modification (adding & ResponseGroup = Offers and & MerchantID = All) did the trick, but there were no names then. (I think one more question I would have, where can I find the index of the possible ResponseGroup parameters?)

In general, as you can see, I really do not have a reliable methodology for this. Is a build-a-ur approach the right way, or will it be more of a problem than it's worth it? Maybe tl; dr above is a better view of the general question.

+6
source share
2 answers

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

 from amazon.api import AmazonAPI amazon = AmazonAPI(ACCESS_KEY, SECRET, ASSOC) results = amazon.search(Keywords = "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 setup.py install 

Hope this helps!

+6
source

If you have problems installing python-amazon-product-api, send the data to the mailing list and they will help you.

0
source

Source: https://habr.com/ru/post/944081/


All Articles