gpt4 book ai didi

node.js - 未处理的拒绝错误 - 骑士

转载 作者:太空宇宙 更新时间:2023-11-04 02:09:49 27 4
gpt4 key购买 nike

我尝试运行稍微修改过的 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 模块。我必须指出,我对 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 并再次下载。

最佳答案

看起来错误来自同一目录中的 .htpasswd 文件。一旦我删除它,一切就正常了

关于node.js - 未处理的拒绝错误 - 骑士,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42764270/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com