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!
php parsing web-scraping phantomjs casperjs
add a comment |
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!
php parsing web-scraping phantomjs casperjs
Try this lib, its working for me. You can also extend and hack it by yourself.
– mr.boris
Jun 2 '17 at 16:23
add a comment |
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!
php parsing web-scraping phantomjs casperjs
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
php parsing web-scraping phantomjs casperjs
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
add a comment |
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
add a comment |
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;
add a comment |
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;
add a comment |
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;
add a comment |
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;
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;
edited Nov 21 at 3:54
answered Apr 23 at 4:33
Grant Miller
4,884132648
4,884132648
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Try this lib, its working for me. You can also extend and hack it by yourself.
– mr.boris
Jun 2 '17 at 16:23