我知道问题的标题看起来很模糊!但仅此而已。
我在我的生产服务器上安装了 nodejs,它让 phantomjs 正常工作,然后我通过 npm install nightmare
安装了 nightmare ,我可以在node_modules中看到它,我尝试了开发人员在github上列出的示例:
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: true })
nightmare
.goto('http://yahoo.com')
.type('input[title="Search"]', 'github nightmare')
.click('#uh-search-button')
.wait('#main')
.evaluate(function () {
return document.querySelector('#main .searchCenterMiddle li a').href
})
.end()
.then(function (result) {
console.log(result)
})
什么都没发生,脚本没有输出任何东西,我将脚本简化为一个简单的单个 goto,对于我服务器上的一个页面,当我通过 node file.js
运行脚本时,该页面从未被调用过
我有 CentOS 6.7,phantomjs 1.1 我还使用最新版本的 phantomjs 在全新的 CentOS 7 安装上测试了它,同样的事情。
我是否缺少某种先决条件?我如何调试自 node script.js
以来的问题没有给出任何输出
更新:显然问题是,梦魇“代替 phantomjs”使用的 electron 需要图形环境,这就是它无法在我的环境中运行的原因。
最佳答案
新版本的 Nightmare 需要 electron
,而不是 PhantomsJs。确保 electron
命令在你的 $PATH 变量中。
安装电子
npm i -g electron-prebuilt
调试:
DEBUG=nightmare* node script.js
关于javascript - Nightmare JS 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36719236/