AL-*_*teb 5 javascript browser-automation node.js phantomjs nightmare
我知道问题的标题看起来很模糊!但就是这样.
我在生产服务器上安装了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)
})
Run Code Online (Sandbox Code Playgroud)
没有发生任何事情,脚本没有输出任何内容,我将脚本简化为简单的单一转到,对于我服务器上的页面,当我通过脚本运行脚本时从未调用过该页面 node file.js
我有CentOS 6.7,phantomjs 1.1我也在最新版本的phantomjs上进行了全新的CentOS 7安装测试,同样的事情.
我错过了某种先决条件还是什么?如何调试问题,因为node script.js没有提供任何输出
更新:显然问题是,电子,噩梦'而不是幻影'使用的电子需要图形环境,这就是它无法在我的环境中运行的原因.
梦魇的新版本要求electron,不是PhantomsJs.确保electron命令在$ PATH变量中.
安装电子
npm i -g electron-prebuilt
要调试:
DEBUG=nightmare* node script.js
| 归档时间: |
|
| 查看次数: |
6887 次 |
| 最近记录: |