如何使用boto mws抓取亚马逊特定订单

2024-10-02 16:33:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我想弄清楚如何使用boto来获取各种Amazon卖家帐户数据。然而,我似乎找不到任何与此相关的例子。 下面的代码不返回错误,但也不返回任何有用的数据(除了注释掉的print orders行,它似乎返回了有用的数据)。在

from boto.mws.connection import MWSConnection 

merchantId = 'zzzz' 
marketplaceId = 'zzz' 
accessKeyId = 'zzzz' 
secretKey = 'secret' 

mws = MWSConnection(accessKeyId, secretKey, Merchant=merchantId) 

orders = mws.list_orders(CreatedAfter='2015-10-23T12:00:00Z', MarketplaceId = 
[marketplaceId])
#print orders

theData = mws.get_order(AmazonOrderId='xxx-xxxxxx-xxxxx')

print theData

有没有关于如何获得上述特定订单相关数据的提示?在


Tags: 数据amazon帐户botoprintmwsorderssecretkey
1条回答
网友
1楼 · 发布于 2024-10-02 16:33:18

您的orders变量看起来不错,这就是打印显示数据的原因,但可能很难理解。据我所见,boto创建自定义对象,这些对象是从web响应中翻译出来的。最有用的文档是Amazon MWS Dev Guide和{a2}。如果你仔细看,你会发现所有的方法都是合二为一的。在

代码的问题在于,list_orders请求返回一个订单列表。您需要解析列表以获得每个订单的ID。由于get_order方法已返回order info,因此get_order调用是多余的。在

虽然下面的代码应该没有测试过。在

from boto.mws.connection import MWSConnection 

merchantId = 'zzzz' 
marketplaceId = 'zzz' 
accessKeyId = 'zzzz' 
secretKey = 'secret' 

mws = MWSConnection(accessKeyId, secretKey, Merchant=merchantId) 

orders = mws.list_orders(CreatedAfter='2015-10-23T12:00:00Z', MarketplaceId = 
[marketplaceId])

for order in orders.ListOrdersResult.Orders.Order:
    this_order_id = order.AmazonOrderId
    theData = mws.get_order(AmazonOrderId = this_order_id)
    print theData
    #do what you want with the data
    #
    #EXAMPLE GET ORDER ITEMS
    order_items = mws.list_order_items(AmazonOrderId = this_order_id)
    print order_items

相关问题 更多 >