我知道问题的标题看起来很模糊!但这就是它了。
我在生产服务器上安装了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)
})
什么都没发生,脚本什么也没输出,我将脚本简化为一个简单的goto,对于服务器上的页面,当我通过以下命令运行脚本时,该页面从未被调用过 node file.js
我有CentOS 6.7,phantomjs 1.1,我也在带有最新版本phantomjs的全新CentOS 7安装上进行了测试,同样。
我是否缺少某种先决条件?由于node script.js
未提供任何输出,我该如何调试问题
更新:显然问题是电子,噩梦“代替phantomjs”使用的电子需要图形环境,这就是为什么它无法在我的环境中运行的原因。
新版本的噩梦需要electron
,而不是PhantomsJs。确保electron
命令位于$ PATH变量中。
安装电子
npm i -g electron-prebuilt
要调试:
DEBUG=nightmare* node script.js
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句