将PhantomJS部署到Node.js应用程序?

7
我知道"在Heroku上运行PhantomJS"与我的问题有关,但略有不同,因为我正在尝试使用一个node应用程序。
我正在尝试部署一个基于phantomJS的casperJS脚本到Node应用程序。我尝试将PhantomJS 64位二进制文件放置在我的应用程序的/bin目录中,并在Heroku上部署,但是当我尝试运行PhantomJS时出现以下错误:
phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory

根据我所读到的,这个问题可以通过安装QtWebKit库来解决,但是Heroku没有安装该库。是否有其他可用的托管服务提供商可以使用或者有方法在Heroku上安装此包?
相关代码:
app.get('/', function(request, response) {
  var sys = require('sys')
  var exec = require('child_process').exec;
  var child;

  //works but gives error while loading shared library libqtwebkit.so.4
  child = exec("phantomjs --version | tr -d '\n'", function(error, stdout, stderr) {
    sys.print('stdout: ' + stdout);
    sys.print('stderr: ' + stderr + '\n');
    response.header('Content-Type', 'application/json');
    response.send('_testcb(stdout:' + stdout + '\nstderr:' + stderr + ')', 200);
    if(error !== null) {
      console.log('exec error: ' + error);
    }
  });
});

我已经注册了Nodester的beta测试,但他们的文档目前仍然非常有限。
编辑:我只需将PhantomJS的lib文件夹复制到我的Node应用程序的根目录中,就能使其正常工作。
1个回答

3

将PhantomJS的lib文件夹复制到您的Node应用程序的根目录中,您也可以尝试在bin或sbin中放置符号链接。关键是必须使用与Node相同的帐户从终端运行它。另外,一旦您使其正常工作,node-phantom是一个不错的npm库来利用PhantomJS。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接