How can I execute casperjs from php?











up vote
2
down vote

favorite












I have a test.js code from manual http://docs.casperjs.org/en/latest/cli.html



var casper = require("casper").create();

casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);

casper.echo("Casper CLI passed options:");
require("utils").dump(casper.cli.options);

casper.exit();


and I can successfully execute it from the terminal '$ casperjs test.js arg1 arg2 arg3 --foo=bar --plop anotherarg'. It's working and this is good, but I need to execute this from the PHP script, I have tried to do it by PHP code:



<?php

function parser() {
try {
echo(exec("C:casperjsbincasperjs.exe C:OpenServerdomainscaspertest.js arg1 arg2 arg3 --foo=bar --plop anotherarg"));
flush();
} catch (Exception $exc) {
echo('error!');
echo $exc->getTraceAsString();
}
}

parser();

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

?>


But I have got a failure 'phantomjs://code/bootstrap.js:110 in __die'.
How can I do it properly? Please help!










share|improve this question
























  • Try this lib, its working for me. You can also extend and hack it by yourself.
    – mr.boris
    Jun 2 '17 at 16:23

















up vote
2
down vote

favorite












I have a test.js code from manual http://docs.casperjs.org/en/latest/cli.html



var casper = require("casper").create();

casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);

casper.echo("Casper CLI passed options:");
require("utils").dump(casper.cli.options);

casper.exit();


and I can successfully execute it from the terminal '$ casperjs test.js arg1 arg2 arg3 --foo=bar --plop anotherarg'. It's working and this is good, but I need to execute this from the PHP script, I have tried to do it by PHP code:



<?php

function parser() {
try {
echo(exec("C:casperjsbincasperjs.exe C:OpenServerdomainscaspertest.js arg1 arg2 arg3 --foo=bar --plop anotherarg"));
flush();
} catch (Exception $exc) {
echo('error!');
echo $exc->getTraceAsString();
}
}

parser();

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

?>


But I have got a failure 'phantomjs://code/bootstrap.js:110 in __die'.
How can I do it properly? Please help!










share|improve this question
























  • Try this lib, its working for me. You can also extend and hack it by yourself.
    – mr.boris
    Jun 2 '17 at 16:23















up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have a test.js code from manual http://docs.casperjs.org/en/latest/cli.html



var casper = require("casper").create();

casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);

casper.echo("Casper CLI passed options:");
require("utils").dump(casper.cli.options);

casper.exit();


and I can successfully execute it from the terminal '$ casperjs test.js arg1 arg2 arg3 --foo=bar --plop anotherarg'. It's working and this is good, but I need to execute this from the PHP script, I have tried to do it by PHP code:



<?php

function parser() {
try {
echo(exec("C:casperjsbincasperjs.exe C:OpenServerdomainscaspertest.js arg1 arg2 arg3 --foo=bar --plop anotherarg"));
flush();
} catch (Exception $exc) {
echo('error!');
echo $exc->getTraceAsString();
}
}

parser();

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

?>


But I have got a failure 'phantomjs://code/bootstrap.js:110 in __die'.
How can I do it properly? Please help!










share|improve this question















I have a test.js code from manual http://docs.casperjs.org/en/latest/cli.html



var casper = require("casper").create();

casper.echo("Casper CLI passed args:");
require("utils").dump(casper.cli.args);

casper.echo("Casper CLI passed options:");
require("utils").dump(casper.cli.options);

casper.exit();


and I can successfully execute it from the terminal '$ casperjs test.js arg1 arg2 arg3 --foo=bar --plop anotherarg'. It's working and this is good, but I need to execute this from the PHP script, I have tried to do it by PHP code:



<?php

function parser() {
try {
echo(exec("C:casperjsbincasperjs.exe C:OpenServerdomainscaspertest.js arg1 arg2 arg3 --foo=bar --plop anotherarg"));
flush();
} catch (Exception $exc) {
echo('error!');
echo $exc->getTraceAsString();
}
}

parser();

putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs");
putenv("DYLD_LIBRARY_PATH");

?>


But I have got a failure 'phantomjs://code/bootstrap.js:110 in __die'.
How can I do it properly? Please help!







php parsing web-scraping phantomjs casperjs






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 27 '17 at 7:12









Shubham Jain

7,51352759




7,51352759










asked Jan 31 '17 at 15:22









ZaurK

327




327












  • Try this lib, its working for me. You can also extend and hack it by yourself.
    – mr.boris
    Jun 2 '17 at 16:23




















  • Try this lib, its working for me. You can also extend and hack it by yourself.
    – mr.boris
    Jun 2 '17 at 16:23


















Try this lib, its working for me. You can also extend and hack it by yourself.
– mr.boris
Jun 2 '17 at 16:23






Try this lib, its working for me. You can also extend and hack it by yourself.
– mr.boris
Jun 2 '17 at 16:23














1 Answer
1






active

oldest

votes

















up vote
2
down vote













You can use a PHP wrapper for CasperJS:




  • php-casperjs


  • casperjs-php (an extension of the above library)


Alternatively, you can use exec() to execute a command:



$result = exec('PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs script.js');
echo $result;





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41961189%2fhow-can-i-execute-casperjs-from-php%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote













    You can use a PHP wrapper for CasperJS:




    • php-casperjs


    • casperjs-php (an extension of the above library)


    Alternatively, you can use exec() to execute a command:



    $result = exec('PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs script.js');
    echo $result;





    share|improve this answer



























      up vote
      2
      down vote













      You can use a PHP wrapper for CasperJS:




      • php-casperjs


      • casperjs-php (an extension of the above library)


      Alternatively, you can use exec() to execute a command:



      $result = exec('PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs script.js');
      echo $result;





      share|improve this answer

























        up vote
        2
        down vote










        up vote
        2
        down vote









        You can use a PHP wrapper for CasperJS:




        • php-casperjs


        • casperjs-php (an extension of the above library)


        Alternatively, you can use exec() to execute a command:



        $result = exec('PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs script.js');
        echo $result;





        share|improve this answer














        You can use a PHP wrapper for CasperJS:




        • php-casperjs


        • casperjs-php (an extension of the above library)


        Alternatively, you can use exec() to execute a command:



        $result = exec('PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs script.js');
        echo $result;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 21 at 3:54

























        answered Apr 23 at 4:33









        Grant Miller

        4,884132648




        4,884132648






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f41961189%2fhow-can-i-execute-casperjs-from-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Berounka

            Sphinx de Gizeh

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...