我不能让噩梦js工作:
我的代码
var Nightmare = require('nightmare'),
nightmare = Nightmare({
show: true
});
console.log('fer');
nightmare
.goto('http://www.google.com')
.type('input[title="Search"]', 'github nightmare')
.click('name[btnK]')
.wait('#main')
.evaluate(function() {
console.log('xxxxxx');
var x = document.querySelector('.srg .g');
var item = x.querySelector("h3").textContent;
console.log(item);
})
.end() // end the Nightmare instance along with the Electron instance it wraps
.then(function(result) {
console.log(result);
});错误
set DEBUG=nightmare & node src\crawler\google-spider.js
nightmare queuing process start +0ms
fer
nightmare queueing action "goto" for http://www.google.com +10ms
nightmare queueing action "type" +23ms
nightmare queueing action "click" +0ms
nightmare queueing action "wait" +1ms
nightmare queueing action "evaluate" +0ms
nightmare running +1ms
nightmare electron child process exited with code 0: success! +5s
(node:7912) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Cannot read property 'focus' of null有没有一种方法可以显示它失败的地方,或者什么是null属性
噩梦电子子进程退出,代码为0:成功!+5s (节点:7912) UnhandledPromiseRejectionWarning:未处理的promise rejection (rejection id: 1):无法读取null的属性'focus‘
发布于 2017-03-10 04:16:04
尝试设置所有噩梦消息:
DEBUG=nightmare*
发布于 2017-03-11 02:58:54
我知道type调用会生成错误,因为只有type调用焦点属性。
此外,console.log('xxxxxx');也不会显示,因为evaluate中的代码在Electron实例上运行。
发布于 2020-09-27 21:23:50
如果网页没有完全加载,就会发生这种情况。尝试在".goto“之后添加".wait(1000)”。
https://stackoverflow.com/questions/42704421
复制相似问题