dongqie8661 2014-02-04 16:04
浏览 56
已采纳

Centos服务器上的CasperJs如何使用php将变量传递给casper js

Okay so i have a casperjs script which does a specific task for me then echoes a result back to me.

i normally use the command

Casperjs script.js "variable1" "variable2"

after a few moments it will echo a results saying either

True

or

False

how can i use php on my server instead of using the command line i would like the php script to execute the command above and then echo the result back to me on my php page

  • 写回答

1条回答 默认 最新

  • douxu9707 2014-02-08 08:44
    关注

    You can use PHP's shell_exec which uses php to call your command, like so:

    .php

    $casperjs = "casperjs";
    $script = "script.js";
    $arg0 = $variable1; 
    $arg1 = $variable2;
    $command = "$casperjs $script $arg0 $arg1";
    $result = shell_exec($command);
    echo $result;   
    

    script.js

    var casper = require('casper').create();
    var arg0 = casper.cli.get(0);
    var arg1 = casper.cli.get(1);
    casper.start('http://example.com/', function() {
      if (this.getTitle() == 'blahblah') {
        this.echo('True');
      } else {
        this.echo('False');
      }
    });     
    casper.run();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?