extends.js
837 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
39
40
/*eslint strict:0*/
/*global CasperError, console, phantom, require*/
var casper = require("casper").create({
loadImages: false,
logLevel: "debug",
verbose: true
});
var links = {
"http://edition.cnn.com/": 0,
"http://www.nytimes.com/": 0,
"http://www.bbc.co.uk/": 0,
"http://www.guardian.co.uk/": 0
};
var fantomas = Object.create(casper);
fantomas.countLinks = function() {
return this.evaluate(function() {
return __utils__.findAll("a[href]").length;
});
};
fantomas.renderJSON = function(what) {
this.echo(JSON.stringify(what, null, " "));
};
fantomas.start();
Object.keys(links).forEach(function(url) {
fantomas.thenOpen(url, function() {
links[url] = this.countLinks();
});
});
fantomas.run(function() {
this.renderJSON(links);
this.exit();
});