我是编程的初学者,我希望有人能帮助我处理这段代码。
我的代码是:-
var i = Object.keys(mws.Result.InventorySupplyList.member).length
console.log(i)
a0 = mws.Result.InventorySupplyList.member[0].ASIN
a1 = mws.Result.InventorySupplyList.member[1]
const amazonScraper = require('amazon-buddy');
(async () => {
try {
// Get single product details by using ASIN id
const product_by_asin_0 = await amazonScraper.asin({ asin: a0 });
console.log(product_by_asin_0)
} catch (error) {
console.log(error);
}
})();
(async () => {
try {
// Get single product details by using ASIN id
const product_by_asin_1 = await amazonScraper.asin({ asin: a0 });
console.log(product_by_asin_1)
} catch (error) {
console.log(error);
}
})();
mws 是 JOSN 对象
const mws = {
"ResponseMetadata": {
"RequestId": "e8698ffa-8e59-11df-9acb-230ae7a8b736"
},
"Result": {
"InventorySupplyList": {
"member": [
{
"SellerSKU": "SampleSKU1",
"ASIN": "B00000K3CQ",
"TotalSupplyQuantity": "20",
"FNSKU": "X0000000FM",
"Condition": "NewItem",
"SupplyDetail": {},
"InStockSupplyQuantity": "15",
"EarliestAvailability": {
"TimepointType": "Immediately"
}
},
{
"SellerSKU": "SampleSKU2",
"ASIN": "B00004RWQR",
"TotalSupplyQuantity": "0",
"FNSKU": "X00008FZR1",
"Condition": "UsedLikeNew",
"SupplyDetail": {},
"InStockSupplyQuantity": "0"
}
]
}
},
"Headers": {
"x-mws-quota-max": "",
"x-mws-quota-remaining": "",
"x-mws-quota-resetson": "",
"x-mws-timestamp": "2018-09-05T06:13:00.276Z",
"content-type": "text/xml",
"content-charset": "",
"content-length": "",
"content-md5": "",
"date": ""
},
"StatusCode": 200
}
我想从 mws 对象中获取 ASIN 并将其插入到其他代码中,该代码将从 amazon.com 抓取详细信息,因为您已经注意到我发现对象 mws 有 2 个 ASIN 并手动将其插入到刮板中。如果您能帮助我如何编写 for 循环以在任何 ASIN 中执行代码。