【问题标题】:How to get the list of price offers on an item from Amazon with python-amazon-product-api item_lookup function?如何使用 python-amazon-product-api item_lookup 函数从亚马逊获取商品的价格优惠列表?
【发布时间】:2010-03-15 06:16:34
【问题描述】:

我正在尝试编写一个函数来获取基于 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

我正在阅读 http://docs.amazonwebservices.com/AWSECommerceService/latest/DG/index.html?ItemLookup.html 并试图让它工作,但它一直只是说:

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

【问题讨论】:

    标签: python amazon-web-services amazon


    【解决方案1】:

    您的回复中似乎没有优惠元素。试试

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

    查看返回的 XML 的样子。

    【讨论】:

      【解决方案2】:

      好的,谢谢。为了向可能有同样问题的其他人回答我自己的问题,执行上述操作的正确方法是:

      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来自 http://pypi.python.org/pypi/python-amazon-product-api

      【讨论】:

      • 谢谢,这对我很有效。只是为了标记我必须将默认编码设置为 utf-8 否则上面的摘录与货币符号斗争
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-22
      相关资源
      最近更新 更多