【问题标题】:Unhandled rejection Error - horseman未处理的拒绝错误 - 骑士
【发布时间】:2017-03-13 22:28:02
【问题描述】:

我正在尝试从 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 在终端上工作,我尝试重新安装节点模块。我必须指出,我对 node 的经验很少。

注意:要安装 phantomjs/horseman,我做了以下操作:

  1. 从phantomjs网站下载tar.gz文件并解压,放在bath /home/bin中
  2. 在 /home/halvor/BettingSource 中运行 npm install phantom
  3. 运行 npm install phantomjs
  4. 运行 npm install node-horseman

我安装 phantomjs 两次都说 phantomjs 在路径中找不到并再次下载。

【问题讨论】:

    标签: node.js phantomjs node-horseman


    【解决方案1】:

    看起来错误来自同一目录中的 .htpasswd 文件。删除后一切正常

    【讨论】:

      【解决方案2】:

      您需要通过以下方式处理承诺拒绝:

      .catch(err => {
          // handle the error here
      });
      

      对于在您的程序中创建的每个承诺。否则它将兑现承诺链中的任何拒绝。

      查看此答案了解更多详情:

      【讨论】:

        猜你喜欢
        • 2017-06-08
        • 1970-01-01
        • 2019-10-27
        • 2017-04-04
        • 2019-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-03
        相关资源
        最近更新 更多