0

I have obtained a list of products based on Search Index, Browse Node and Keyword from the Amazon Product Advertising API using Python. Now I have to get the Sales Rank of the list of 20 products that I have obtained, but I am not able to print the value. I can sort the list by the products' Sales Rank but this does not give me the value of the Sales Rank corresponding to each product.

Here is my code so far:

from amazonproduct import api
import lxml

api = API(locale='us')

def search(index, keyword):
    items = api.item_search(index, BrowseNode = '', Keywords = keyword)
    return items

result = search("Books", "Harry Potter")

count = 0
for item in result:
    print "%s" % (item.ItemAttributes.Title)
    count += 1
    if count == 20:
        break

I have just recently looked into the Amazon API and I'm fairly unfamiliar with it, so I've just been reading the documentation and relying on it to figure stuff out.

Any help in printing the Sales_Rank would be greatly appreciated. Thanks a lot!

Ken White
  • 117,855
  • 13
  • 197
  • 405
Richa Netto
  • 245
  • 1
  • 4
  • 8

1 Answers1

0

Try this:

print "%s" % (item.SalesRank)

You can view the contents of the item array using the pprint class. See this related post on how to display the contents of an array in Python: How to print a list in Python "nicely"

Community
  • 1
  • 1
Nadir Latif
  • 3,223
  • 1
  • 13
  • 22