php-casperjs: Can not find CasperJS
Hello, I’m having trouble running the example code.
I installed phantomjs and casperjs.
I installed php-casperjs
And when I run the example I get:
Fatal error: Class ‘Browser\Casper’ not found in C:\wamp\www\crawler\ajax.php on line 5
When I removed the:
namespace Browser;
from Casper.php and included Casper.php manually:
include 'vendor/phpcasperjs/phpcasperjs/src/Browser/Casper.php';
I get:
Fatal error: Uncaught exception ‘Exception’ with message ‘Can not find CasperJS.’ in C:\wamp\www\crawler\vendor\phpcasperjs\phpcasperjs\src\Browser\Casper.php on line 560 ( ! ) Exception: Can not find CasperJS. in C:\wamp\www\crawler\vendor\phpcasperjs\phpcasperjs\src\Browser\Casper.php on line 560
Finally I went through the Casper.php file and changed this:
private $path2casper = '/usr/local/bin/'; //path to CasperJS
for all paths I could think of without any success.
Could you please help me? thankyou
About this issue
- Original URL
- State: open
- Created 8 years ago
- Comments: 25 (3 by maintainers)
@antoiba86 I attempted this as i’m using Ubuntu and unfortunately it didn’t work either (although it may have contributed to me finding a successful workaround afterwards so i’d recommend trying this as well). My debug steps are below hopefully they might help someone else.
I noticed that on my Laravel/Homestead box the path2casper was:
/usr/local/bin/casperjs
When running casperjs on terminal it was actually running in different directory:
CasperJS version 1.1.3 at /usr/lib/node_modules/casperjs, using phantomjs version 2.1.1
Changing the path2casper to the above didn’t work I echoed out exec() command and ran it in terminal and received an error telling me that casperjs was a directory, I navigated to the directory and found that my casperJS install was actually within the bin of that folder:
/usr/lib/node_modules/casperjs/bin/casperjs
Changing the following lines in my Casper.php finally did the trick:
$this->path2casper = '/usr/lib/node_modules/'; //new path to CasperJS exec($this->path2casper . 'casperjs/bin/casperjs ' . $filename . $options, $output);