Run/Execute CasperJS script at the server by clicking a button on webpage or from a php web API or from javascript.

2,805 views
Skip to first unread message

lavesh bhandari

unread,
Aug 20, 2013, 3:13:55 AM8/20/13
to casp...@googlegroups.com
On a high level what I want is :

1) User visits my site. Enter an Input and click a button like submit.
2) After clicking the button my casperJS script should get trigered at the server side and return a result in JSON format back.
3) The result is further processed at the client side

Any ideas how can I achieve step 2 

bruce

unread,
Aug 20, 2013, 4:54:16 AM8/20/13
to casp...@googlegroups.com
Hey.

If I understand your need, you have a website, you want a user to come to your site, and to then submit a btn. The btn would then invoke an action on the server side, that would run the casper app, and to return the results to the user on the clientside.

If I've got what you want to do, you can accomplish this by having the btn trigger an ajax process back to the serverside, that triggers the serverside, and returns the results to the client

the serverside would then run the casper function from the exec/system to run the casper app/function.

hope that helps




--
CasperJS homepage & documentation: http://casperjs.org/
CasperJS @github: https://github.com/n1k0/casperjs
 
You received this message because you are subscribed to the Google Groups "casperjs" group.
Visit this group at http://groups.google.com/group/casperjs?hl=en.
---
You received this message because you are subscribed to the Google Groups "CasperJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to casperjs+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

lavesh bhandari

unread,
Aug 20, 2013, 5:17:05 AM8/20/13
to casp...@googlegroups.com
Hi bert,

You got it right. What I am doing is clicking the button invoking ajax process in php (test.php). The php contains exec 'casperjs sample.js'.

This php script is not executing he casperjs. On checking webservererror log am getting the following error 

'C:/xampp/htdocs/proxy.php' not found or unable to stat, referer: RefererString
'casperjs' is not recognized as an internal or external command,
operable program or batch file.

bruce

unread,
Aug 20, 2013, 5:25:03 AM8/20/13
to casp...@googlegroups.com
 can you run the casper command/app from the cmdline?

you should be able to run the exact same line/cmd from the exec/system function of the php app

you might need to check the perms of the app, as well as ensure that the web app has privs to run the casper process


lavesh bhandari

unread,
Aug 20, 2013, 5:39:04 AM8/20/13
to casp...@googlegroups.com
Yes I can run it from command line but am not able to run it from php. I changed the php call to echo exec('C:\casperjs\batchbin\casperjs .\sample.js');
and now the error is : 'phantomjs' is not recognized as an internal or external command,
operable program or batch file.

I think its not able to find the phantomjs executable file

lavesh bhandari

unread,
Aug 20, 2013, 6:18:19 AM8/20/13
to casp...@googlegroups.com
It worked by moving CasperJS & PhantomJS executable file in the directory server (/html) 

Julien Trachez

unread,
Mar 12, 2014, 6:15:08 AM3/12/14
to casp...@googlegroups.com
Hi, thank,

Can you see me your folder ?  because i have same problem :/

thx

Gabe Misura

unread,
Jul 15, 2015, 12:12:33 PM7/15/15
to casp...@googlegroups.com
Use the full path to casperjs.exe (or binary), moving files into html doesn't sound like a good idea (security wise).

Sahil Goyal

unread,
Mar 30, 2016, 12:46:50 AM3/30/16
to CasperJS
Hello Julien,,

Did you get any solution for the above problem because I am also facing the same issue?

Thanks in Advance... :)

Sahil Goyal

unread,
Mar 30, 2016, 2:00:01 AM3/30/16
to CasperJS
Hello Lavesh,

Can you share this file structure with me because I am also stuck with same issue.

Thanks in Advance.. :)

Aaron Loften

unread,
Aug 20, 2016, 8:34:21 AM8/20/16
to CasperJS
Have you researched what impact this may have on SEO, Security sites, and whether or not its a general breach of contract on your webhost services provider?

I feel like this may cause a website to get blacklisted, If an seo service picked up the action. Sites like "webutation" or "avg" or even "norton" may consider the action unpredictable and unsafe, warning users that arrived on the site to navigate away..

Ive had some conversations about this with a godaddy csr or two that didnt go my way. Threats to close my account if I were implement this.

Let us know if you check up on these things. My way of doing this without getting trouble is pinging my website from a computer using a timer and performing multiple instances/actions on casper at the same time. My way is not idea, but prevents any kind of repercussions. Im curious if this affects your end-goal.

Ken

unread,
May 25, 2017, 7:31:42 PM5/25/17
to CasperJS

When calling from PHP can use something like this. Key is to define PHANTOMJS_EXECUTABLE location. Below is for Linux, probably can modify to work Windows or add the executables location to path.


$exec_result = exec("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs /usr/local/bin/casperjs /full_path/script.js " . $_GET['PARAMETER']);

Reply all
Reply to author
Forward
0 new messages