首页 > node > debian8上面跑node的nightmare库

debian8上面跑node的nightmare库

  最近想把nightmare移植到debian上面,但是使用npm安装上去之后,发现不能运行。因为NightmareJS使用Electron,不能运行的话肯定是缺少让Electron运行的库啦,只要安装好应该就可以了。参考 在Amazon Linux上使用NightmareJS/Electron,感谢这篇文章给提供的思路。

$ cd node_modules/nightmare/node_modules/electron-prebuilt/dist
$ ldd electron | grep 'not found'
libgtk-x11-2.0.so.0 => not found    
libgdk-x11-2.0.so.0 => not found
libatk-1.0.so.0 => not found        
libXi.so.6 => not found             
libXcursor.so.1 => not found      
libXfixes.so.3 => not found
libXdamage.so.1 => not found     
libXrandr.so.2 => not found         
libXcomposite.so.1 => not found      
libXtst.so.6 => not found            
libXss.so.1 => not found             
libgconf-2.so.4 => not found     
libnss3.so => not found               
libnssutil3.so => not found
libsmime3.so => not found
libnspr4.so => not found
libasound.so.2 => not found        
libcups.so.2 => not found            
libdbus-1.so.3 => not found

  一看缺少这么多的库,不用怕,使用apt-get可以快速的安装,参考文章上面使用的yum安装的,也可能以后会因为版本不一样缺少的库也不一样,要举一反三,缺少什么安装什么,search一下都能搞定,下面是我用apt-cache一个一个搜索出来的库的对照,有的因为依赖关系,一次安装好几个。

libgtk-x11-2.0.so.0 => not found     libgtk2.0-0
libgdk-x11-2.0.so.0 => not found     ---
libatk-1.0.so.0 => not found         libatk1.0-0
libXi.so.6 => not found              xterm
libXcursor.so.1 => not found         libxcursor1
libXfixes.so.3 => not found          ---
libXdamage.so.1 => not found         libxdamage1
libXrandr.so.2 => not found          libxrandr2
libXcomposite.so.1 => not found      libxcomposite1
libXtst.so.6 => not found            libxtst6
libXss.so.1 => not found             libXss1
libgconf-2.so.4 => not found         libgconf2-4
libnss3.so => not found              libnss3 libnss3-tools
libnssutil3.so => not found          ---
libsmime3.so => not found            ---
libnspr4.so => not found             ---
libasound.so.2 => not found          libasound2
libcups.so.2 => not found            libcups2
libdbus-1.so.3 => not found          ---

再运行ldd,应该会看到一个空的输出

$ ldd electron | grep 'not found'

  要让Electron真正运行起来,只解决依赖库是不够的,我们还需要配置X Server

# 安装X Server
apt-get install xserver-xorg xterm
# 安装 X drivers
apt-get install xserver-xorg-input-all xserver-xorg-video-all
# 安装 xvfb
apt-get install xvfb

  好了,现在我们就可以使用xvfb-run在SSH中运行nightmare了

$ xvfb-run -a --server-args="-screen 0 1024x768x24" node baidu.js 
百度一下,你就知道
//baidu.js
var Nightmare = require('nightmare');
var nightmare = Nightmare({ show: false });
nightmare
  .goto('https://www.baidu.com')
  .evaluate(function () {
    return document.title;
  })
  .end()
  .then(function (result) {
    console.log(result)
  })
  .catch(function (error) {
    console.error('Search failed:', error);
  });
  1. 还没有评论
评论提交中, 请稍候...

留言


可以使用的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks