无论做什么,我都无法递归调用函数。我试过返回并存储到变量和许多其他东西中,但是它只被调用过一次?
var scrape = () => {
var waitTime = randomIntFromInterval(1000, 10000);
nightmare.goto('http://...')
.wait(waitTime)
.evaluate(() => {
var data = [];
// ... doing work to get data from browser here
return data
})
.end()
.then((result) => {
console.log('scraped successfully!' + new Date());
scrape();
}
)
}
scrape();
我以为最终的
.then()
意味着 promise 已经完成并且成功了吗? 更新:
似乎删除
.end()
已解决了我的问题。我不完全理解 Nightmare 文档https://github.com/segmentio/nightmare,它说它完成了所有队列操作。我从一个示例中提取了一些代码,其中有end()
。删除它会带来任何影响吗?
最佳答案
你能试试这个流程吗
var scrape = () => {
var waitTime = randomIntFromInterval(1000, 10000);
nightmare.goto('http://...')
.then((result) => {
console.log('scraped successfully!' + new Date());
////do the end process here////
scrape();
}
)
}
scrape();
关于javascript - 为什么我的递归函数不会从promise调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50634938/