2

I have a casperJS script which returns JSON when run via commandline. I want to make an API preferably in PHP which runs the script as in commandline (casperJS sample.js) and returns the JSON as result.

2 Answers 2

3

You can use php-casperjs library which is a simple wrapper for casperjs.

Sign up to request clarification or add additional context in comments.

Comments

3

I think you can use php exec() function as shown below to do this

echo exec("/home/user/casperjs/bin/casperjs /full/path/to/your_script.js");

3 Comments

Awesome! Just wondering how do you pass value on each exec? Cause I need to pass a unique search term.
@3zzy You could pass it as command line arguments echo exec("/home/user/casperjs/bin/casperjs /full/path/to/your_script.js arg1 arg2"); , read more about casperjs command line arguments here
Ah man, a bit late. I spent like a day setting up PHP-Casper which is okay but too slow and doesn't work with nohup .. Will try this, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.