梦魇JS不工作 [英] Nightmare JS not working
问题描述
我知道问题的标题看起来很模糊!但就是这样。
我在我的生产服务器上安装了nodejs,其中phantomjs工作正常,然后我通过安装了噩梦npm install nightmare
,我可以在node_modules中看到它,我尝试了github上开发人员列出的例子:
var梦魇=要求('梦魇');
var nightmare =梦魇({show:true})
噩梦
.goto('http://yahoo.com')
.type('输入[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(结果)
})
没有任何反应,脚本没有没有输出任何内容,我将脚本简化为一个简单的单一转到,对于我服务器上的页面,当我通过节点file.js
<运行脚本时,从未调用该页面/ p>
我有CentOS 6.7,phantomjs 1.1
我还在最新版本的phantomjs上进行了全新的CentOS 7安装测试,同样的事情。
我错过了某种先决条件或什么?如何调试问题,因为节点script.js
没有提供任何输出
更新:显然问题是,噩梦'而不是幻影'所使用的电子需要图形环境,这就是它无法在我的环境中运行的原因。
新版Nightmare需要电子
,而非PhantomsJs。确保 electron
命令位于$ PATH变量中。
安装电子
npm i -g electron -prebuilt
调试:
DEBUG = nightmare * node script.js
I know the title of the question looks very vague! But that's there's to it.
I installed nodejs on my production server, which had phantomjs working properly, then I installed nightmare via npm install nightmare
, I can see it in node_modules, I tried the example listed by the developers on 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)
})
Nothing happened, the script did not output anything, I simplified the script to a simple single goto, for a page on my server, the page was never called when I ran the script via node file.js
I have CentOS 6.7, phantomjs 1.1 I also tested it on a fresh CentOS 7 installation with latest version of phantomjs, same thing.
Am I missing some kind of prerequisite or something? How do I debug the issue since node script.js
is not giving any output
UPDATE: Apparently the problem is, electron, which is used by nightmare 'instead of phantomjs' requires a graphical enviroment, which is why it fails to run in my enviroment.
New version of Nightmare requires electron
, Not PhantomsJs. Make sure electron
command is in your $PATH variable.
Install Electron
npm i -g electron-prebuilt
To debug:
DEBUG=nightmare* node script.js
这篇关于梦魇JS不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!