将phantomJS部署到node.js应用程序?

时间:2022-06-13 15:42:27

I realize "Running PhantomJS on Heroku" is a related but slightly different question as I am trying to use a node app.

我意识到“在Heroku上运行PhantomJS”是一个相关但略有不同的问题,因为我正在尝试使用节点应用程序。

I'm having trouble deploying a casperJS (based on phantomJS) script for a node app. I've tried deploying to Heroku by placing the PhantomJS 64-bit binary in my app's /bin directory, but I get the following error when I try to run PhantomJS:

我在为节点应用程序部署casperJS(基于phantomJS)脚本时遇到问题。我已经尝试通过将PhantomJS 64位二进制文​​件放在我的应用程序的/ bin目录中来部署到Heroku,但是当我尝试运行PhantomJS时出现以下错误:

phantomjs: error while loading shared libraries: libQtWebKit.so.4: cannot open shared object file: No such file or directory

From what I've read this can be solved by installing the QtWebKit library, but Heroku does not have this installed. Is there another hosting provider I could use that will work or a way to install this package on Heroku?

从我所看到的,这可以通过安装QtWebKit库来解决,但Heroku没有安装它。是否有其他我可以使用的托管服务提供商可以使用或在Heroku上安装此软件包的方法?

Relevant code:

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);
    }
  });
});

I've signed up for beta-testing on Nodester but their documentation is still pretty limited at this point.

我已经注册了Nodester的beta测试,但是他们的文档在这一点上仍然非常有限。

EDIT: I was able to get it working by simply copying the lib folder of PhantomJS to the root directory of my node app.

编辑:我能够通过简单地将PhantomJS的lib文件夹复制到我的节点应用程序的根目录来实现它。

1 个解决方案

#1


3  

Copy the lib folder of phantomjs to the root directory of your node app You could also try putting a sym link in bin or sbin The key is that is has to run from terminal using the same account that node runs on. Also, node-phantom is a good npm library to utilize phantomjs, once you get it working.

将phantomjs的lib文件夹复制到节点应用程序的根目录您还可以尝试在bin或sbin中放置sym链接关键是必须使用节点运行的同一帐户从终端运行。此外,node-phantom是一个很好的npm库,可以在使用phantomjs后使用它。

#1


3  

Copy the lib folder of phantomjs to the root directory of your node app You could also try putting a sym link in bin or sbin The key is that is has to run from terminal using the same account that node runs on. Also, node-phantom is a good npm library to utilize phantomjs, once you get it working.

将phantomjs的lib文件夹复制到节点应用程序的根目录您还可以尝试在bin或sbin中放置sym链接关键是必须使用节点运行的同一帐户从终端运行。此外,node-phantom是一个很好的npm库,可以在使用phantomjs后使用它。