googlelinks.js
981 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var getLinks = function getLinks() {
var links;
links = document.querySelectorAll("h3.r a");
return Array.prototype.map.call(links, function(e) {
return e.getAttribute("href");
});
};
var links = [];
var casper = require('casper').create();
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);
// search for 'phantomjs' from google form
this.fill('form[action="/search"]', {
q: "phantomjs"
}, true);
});
casper.then(function() {
// concat results for the 'phantomjs' search
links = links.concat(this.evaluate(getLinks));
});
casper.run(function() {
// display results
this.echo("" + links.length + " links found:");
this.echo(" - " + links.join("\n - "));
this.exit();
});