dongxiezhuo8852 2015-11-13 18:01
浏览 117
已采纳

在Web服务器上安装CasperJS和PhantomJS

I put phantomjs-1.9.7-macosx and casperjs 1.1-beta into two separate folders. In the root directory I have index.html, where I'm calling hello.js which is a minimal scraping script from casparjs getting started example. Obviously I'm getting:

Uncaught ReferenceError: require is not defined

since require() does not exist in the browser/client-side.

Then I tried to set the environment with PHP and execute it

putenv("PHANTOMJS_EXECUTABLE=/phantomjs/bin/phantomjs");
echo "Running PhantomJS version: ";
echo exec('/phantomjs/bin/phantomjs --version 2>&1');
echo "Running CasperJS version: ";
echo exec('/casperjs/bin/casperjs --version 2>&1');

but the server responded with a new error:

Warning: exec() has been disabled for security reasons in

I couldn't find any workaround to that one, so I decided to do one step back and to run this on a local XAMPP web server. I followed the answer from a similar problem, but CasperJS responded with an error again:

[Errno 13] Permission denied; did you install phantomjs?

I tried "sudo chmod a+rx" for the directories, but with no success.

I cannot find solutions to any of my problems. I used these simple examples just to test. All of it run fine from the terminal (as well as PHP files on a local web server). The problem I believe, is in integration on the server, either local or web.

  • 写回答

1条回答 默认 最新

  • dongzhuang2030 2015-11-13 20:34
    关注

    PhantomJS is a browser that you need to invoke to execute some navigational script on it. This script may open pages and do something with the results. CasperJS is built on top of PhantomJS and simplifies a lot of the work needed to write PhantomJS scripts.

    A PhantomJS/CasperJS script cannot be executed in the client browser. It needs to be invoked on the server, run inside of CasperJS/PhantomJS and the results can be passed to the client.

    You either need to

    • enable exec/shell_exec or
    • use write your CasperJS script as a web server.

    PhantomJS provides the web server module which you can use to let PhantomJS accept HTTP requests, open a page with some CasperJS code, do something and write the result to the response. You could start a single CasperJS instance in this way and let PHP forward the request to CasperJS.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里