我试图从horsemanjs运行示例代码稍加修改:
var Horseman = require('node-horseman');
var horseman = new Horseman();
horseman
.userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
.open('http://www.google.com')
.type('input[name="q"]', 'github')
.click('[name="btnK"]')
.keyboardEvent('keypress', 16777221)
.waitForSelector('div.g')
.plainText()
.log()
.close();
几天前它确实奏效了,但突然决定不这样做。我跑的时候会得到这个:
➜ Debug=horseman node test.js
horseman using PhantomJS from phantomjs-prebuilt module +0ms
horseman .setup() creating phantom instance 1 +3ms
horseman phantom created +195ms
horseman .close(). +13ms
Unhandled rejection Error
at IncomingMessage.<anonymous(/home/halvor/BettingSource/node_modules/node-phantom-simple/node-phantom-simple.js:612:14)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
使用Bluebird调试:
➜ BettingSource DEBUG=horseman BLUEBIRD_DEBUG=1 node test.js
horseman using PhantomJS from phantomjs-prebuilt module +0ms
horseman .setup() creating phantom instance 1 +3ms
horseman phantom created +149ms
horseman .close(). +16ms
Unhandled rejection HeadlessError: Error parsing JSON from phantom: SyntaxError: Unexpected end of JSON input
Data from phantom was:
at IncomingMessage.<anonymous> (/home/halvor/BettingSource/node_modules/node-phantom-simple/node-phantom-simple.js:612:14)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:188:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
From previous event:
at prepare (/home/halvor/BettingSource/node_modules/node-horseman/lib/index.js:54:9)
at new Horseman (/home/halvor/BettingSource/node_modules/node-horseman/lib/index.js:155:15)
at Object.<anonymous> (/home/halvor/BettingSource/test.js:2:16)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:425:7)
at startup (bootstrap_node.js:146:9)
at bootstrap_node.js:540:3
Phantomjs从终端工作,我试图重新安装节点模块。我必须注意,对节点的经验很少。
注意:要安装phantomjs / horseman,我执行了以下操作:
我安装了phantomjs的两次都表示在路径中找不到phantomjs并再次下载它。
答案 0 :(得分:0)
看起来错误来自同一目录中的.htpasswd文件。一旦我删除它一切正常
答案 1 :(得分:0)
您需要处理承诺拒绝:
.catch(err => {
// handle the error here
});
为您的程序中创建的每个承诺。否则它将兑现承诺链中的任何拒绝。
有关详细信息,请参阅此答案: