【发布时间】:2016-11-04 12:40:38
【问题描述】:
我正在尝试在本地运行带有噩梦 js 的 cron。 不幸的是我有这个错误。
Unhandled rejection (<{"message":"navigation error","code":-...>, no stack trace)
我想知道这是否与噩梦需要图形界面这一事实有关?
感谢您的帮助,
编辑
在我的 cron 中,我有一个 Promise 函数,它由 cron 和 Promise 组成。
var job = new CronJob('* */10 * * * *', function() {
crawl()
}, function () {
console.log("crawl ended")
},
true
);
job.start();
这是噩梦的样子:
var Nightmare = require('nightmare');
var nightmare = Nightmare({
typeInterval: 300,
show: true
});
nightmare
.goto('https://pageThatRequireToLoginThenDiplayJsonAsText.com')
.type('[name=email]', '')
.wait(1000)
.type('[name=email]', 'myemail')
.wait(1000)
.type('[name=password]', '')
.wait(1000)
.type('[name=password]', 'mypassword')
.click('[type=submit]')
.wait(25000)
.wait(25000)
.evaluate(function (page, done) {
document.documentElement
done()
})
.end()
.then(function (result) {
// fs.writeFileSync('testOutput.json', JSON.stringify(result));
console.log(JSON.stringify(result))
})
.catch(function (error) {
console.error('failed:', error);
});
当我在没有 cron 的情况下运行 crawl 函数时,它工作得很好。
【问题讨论】:
标签: javascript cron nightmare