Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding casperjs example

  • Loading branch information...
commit 3c11b14d31727933d08305871e74634c232937cb 1 parent 53eeede
@carimura carimura authored
View
9 binary/casperjs/casper.worker
@@ -0,0 +1,9 @@
+runtime "binary"
+exec "run.sh"
+
+# Include the Javascript file that Phantom will execute
+file "googlelinks.js"
+dir "casperjs"
+
+# This line will grab Phantom JS 1.6.0 (the proper version), compile it, and include it with your code package
+build 'curl http://phantomjs.googlecode.com/files/phantomjs-1.6.0-linux-x86_64-dynamic.tar.bz2 -o p.tar.bz2 && tar xf p.tar.bz2 && rm p.tar.bz2'
1  binary/casperjs/casperjs
@@ -0,0 +1 @@
+Subproject commit 5428865b20be4ff2914a1c3883a1557113237b60
View
32 binary/casperjs/googlelinks.js
@@ -0,0 +1,32 @@
+var links = [];
+var casper = require('casper').create();
+
+function getLinks() {
+ var links = document.querySelectorAll('h3.r a');
+ return Array.prototype.map.call(links, function(e) {
+ return e.getAttribute('href')
+ });
+}
+
+casper.start('http://google.fr/', function() {
+ // search for 'casperjs' from google form
+ this.fill('form[action="/search"]', { q: 'casperjs' }, true);
+});
+
+casper.then(function() {
+ // aggregate results for the 'casperjs' search
+ links = this.evaluate(getLinks);
+ // now search for 'phantomjs' by filling the form again
+ this.fill('form[action="/search"]', { q: 'phantomjs' }, true);
+});
+
+casper.then(function() {
+ // aggregate results for the 'phantomjs' search
+ links = links.concat(this.evaluate(getLinks));
+});
+
+casper.run(function() {
+ // echo results in some pretty fashion
+ this.echo(links.length + ' links found:');
+ this.echo(' - ' + links.join('\n - ')).exit();
+});
View
4 binary/casperjs/iron.json
@@ -0,0 +1,4 @@
+{
+ "token": "YOUR_TOKEN",
+ "project_id": "PROJECT_ID"
+}
View
2  binary/casperjs/run.sh
@@ -0,0 +1,2 @@
+PATH=$PATH:`pwd`/phantomjs-1.6.0-linux-x86_64-dynamic/bin/
+casperjs/bin/casperjs googlelinks.js
Please sign in to comment.
Something went wrong with that request. Please try again.