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 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退