@@ -13,7 +13,7 @@ Casper.js is a navigation utility for [PhantomJS](http://www.phantomjs.org/). It
## Quickstart
In the following example, we'll query google for two terms consecutively, `capser` and `homer`, and aggregate the result links in a standard Array. Running the script will output a standard JSON string containing both the logs and the results:
In the following example, we'll query google for two terms consecutively, `capserjs` and `phantomjs`, and aggregate the result links in a standard Array. Then we'll output the result to the console:
``` javascript
functiongetLinks(){
...
...
@@ -28,30 +28,35 @@ function getLinks() {
varlinks=[];
varcasper=newphantom.Casper({
logLevel:"debug",
verbose:true
logLevel:"info",// we only want "info" or higher level log messages
loadImages:false,// do not download images to save bandwidth
loadPlugins:false,// do not load plugins to save kitten
verbose:true// write log messages to the console
})
.start('http://google.fr/')
.then(function(self){
// search for 'casperjs' from google form
self.fill('form[name=f]',{
q:'casperjs'
},true);
})
.then(function(self){
// aggregate results for the 'casperjs' search
links=self.evaluate(getLinks);
// now search for 'phantomjs' by fillin the form again
self.fill('form[name=f]',{
q:'plop'
q:'phantomjs'
},true);
})
.then(function(self){
// aggregate results for the 'phantomjs' search
links=links.concat(self.evaluate(getLinks));
})
.run(function(self){
self.echo(JSON.stringify({
result:self.result,
links:links
},null,' '));
self.exit();
// echo results in some pretty fashion
self.echo(links.map(function(i){
returni.title+' ('+i.href+')';
}).join('\n')).exit();
})
;
```
...
...
@@ -60,104 +65,39 @@ var casper = new phantom.Casper({
Paris JS #10 : Introduction à PhantomJS, un navigateur webkit ... (http://svay.com/blog/index/post/2011/08/31/Paris-JS-10-%3A-Introduction-%C3%A0-PhantomJS,-un-navigateur-webkit-headless)