我知道问题的标题看起来很模糊!但仅此而已。
我在我的生产服务器上安装了nodejs,其中phantomjs工作正常,然后我通过安装了噩梦npm install 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)
})
什么也没发生,脚本没有输出任何内容,我将脚本简化为简单的单个转到,对于我的服务器上的页面,当我通过运行脚本时从未调用该页面node file.js
我有 CentOS 6.7,phantomjs 1.1
我还在新安装的 CentOS 7 上使用最新版本的 phantomjs 进行了测试,同样的事情。
我是否缺少某种先决条件或其他东西?我如何调试这个问题node script.js
没有给出任何输出
更新:显然问题是,噩梦“而不是phantomjs”使用的电子需要图形环境,这就是它无法在我的环境中运行的原因。
新版本的噩梦需要electron
,不是PhantomsJs。确保electron
命令位于您的 $PATH 变量中。
安装电子
npm i -g electron-prebuilt
调试:
DEBUG=nightmare* node script.js
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)