[英]How to write for loop to take property from object and insert it in function javascript
I am beginner in programming and I wish someone help me on this code.我是编程初学者,我希望有人帮助我解决此代码。
My code is:-我的代码是:-
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 is JOSN object 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
}
I want to take the ASIN from the mws object and insert it in the other code which will scrape the details from amazon.com , as you notice already that I figured out the object mws has 2 ASIN and did insert it manually in the scraper.我想从 mws 对象中获取 ASIN 并将其插入其他代码中,该代码将从 amazon.com 抓取详细信息,因为您已经注意到我发现对象 mws 有 2 个 ASIN 并确实将其手动插入到刮板中。 If you can help me how to write for loop to do the code in what ever ASINs.
如果您能帮助我如何编写 for 循环以在任何 ASIN 中执行代码。
const Promise = require('bluebird');
const amazonScraper = require('amazon-buddy');
const requests = Promise.all(Object.keys(mws["Result"]["InventorySupplyList"]["member"])
.map(member => amazonScraper.asin({ asin: member["ASIN"] }));)
requests.then(responces => console.log(responces))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.