How to get the list of price offers on an item from Amazon with python-amazon-product-api item_lookup function?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-06 07:15:41

问题


I am trying to write a function to get a list of offers (their prices) for an item based on the ASIN:

def price_offers(asin):
    from amazonproduct import API, ResultPaginator, AWSError
    from config import AWS_KEY, SECRET_KEY
    api = API(AWS_KEY, SECRET_KEY, 'de')
    str_asin = str(asin)
    node = api.item_lookup(id=str_asin, ResponseGroup='Offers', Condition='All', MerchantId='All')
    for a in node:
        print a.Offer.OfferListing.Price.FormattedPrice

I am reading http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ItemLookup.html and trying to make this work, but all the time it just says:

Failure instance: Traceback: <type 'exceptions.AttributeError'>: no such child: {http://webservices.amazon.com/AWSECommerceService/2009-10-01}Offer

回答1:


Seems like there is no Offer element in your response. Try

node = api.item_lookup(...)
from lxml import etree
print etree.tostring(node, pretty_print=True)

to see how the returned XML looks like.




回答2:


OK, thanks. To anwser my own question for others who might have the same problem, the right way to do the above is:

def price_offers(asin):
    from amazonproduct import API, ResultPaginator, AWSError
    from config import AWS_KEY, SECRET_KEY
    api = API(AWS_KEY, SECRET_KEY, 'de')
    str_asin = str(asin)
    node = api.item_lookup(id=str_asin, ResponseGroup='Offers', Condition='All', MerchantId='All')
    for a in node.Items.Item.Offers.Offer:
        print a.OfferListing.Price.FormattedPrice

amazonproduct comes from http://pypi.python.org/pypi/python-amazon-product-api



来源:https://stackoverflow.com/questions/2445420/how-to-get-the-list-of-price-offers-on-an-item-from-amazon-with-python-amazon-pr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!