[英]Get query results from Sequelize then run a scraper job result by result
I am trying to query a DB through Sequilize, then I would like to use each record returned to run a Scraping job (using puppeteer).我正在尝试通过 Sequilize 查询数据库,然后我想使用返回的每条记录来运行 Scraping 作业(使用 puppeteer)。 I would like it to run only record by record, like we start scraping the first record, then wait the first one to finish then move on to the second record.我希望它只逐条记录运行,就像我们开始抓取第一条记录,然后等待第一条记录完成,然后转到第二条记录。
Here is my code so far Scraping controller:到目前为止,这是我的代码 Scraping 控制器:
exports.directFind = async (vin, res) => {
if (vin) {
let browserInstance = browserObject.startBrowser();
await scraperController(browserInstance,vin)
.then(results => {
return res(results)
});
}
};
Function to send notification with the scraper使用刮板发送通知的功能
const sendNotif = async () => {
Vins.findAll({raw : true}).then(async (vins) => {
await vins.map(async (vin) => {
console.log(vin.vin)
await search.directFind(vin.vin,function(res) {
status.findLatestVinStatus(vin.id,function(latestVINStatus) {
if (latestVINStatus.vmacs3CharCode == res.result.order.vmacs3CharCode || latestVINStatus.gobStatusCode == res.result.order.gobStatusCode) { //to be cganged for prod
console.log("we need to send notif")
//sendEmail(res.result)
}
});
})
console.log('end')
});
})
}
Thanks谢谢
You can use a for loop to go over the results one by one:您可以使用 for 循环一一查看结果:
for (const vin of await Vins.findAll({raw : true})) {
await search.directFind(vin.vin, res => { // ... })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.