我需要等待每個專案,而不是呼叫另一個函式。
await readCSV(filename).then(fileArray => {
for (let element of fileArray) {
console.log(element)
searchItem(element) //<--- Wait each element will finish this function()
}
})
的功能searchItem()是:
async function searchItem(item) {
console.log('2) Avvio Browser for ' item.codice_kromeda)
await page.goto('url_part1' item.codice_kromeda 'url_part2');
await page.waitForSelector('.si-search-result')
let list = await page.$$('.si-search-result');
console.log(list)
return true
}
uj5u.com熱心網友回復:
由于searchItem()已經回傳了一個在搜索完成時解決的承諾,您可以簡單地重組以正確使用await:
const fileArray = await readCSV(filename);
for (let element of fileArray) {
console.log(element);
await searchItem(element);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/472499.html
上一篇:在pm2服務器上運行npmstart回傳錯誤:找不到模塊Cors
下一篇:正確使用DOTENV
