1 Star 0 Fork 0

代码神童 / casperjsDemo

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
node-countlinks.js 1011 Bytes
一键复制 编辑 原始数据 按行查看 历史
guoa1234@163.com 提交于 2017-09-01 09:13 . casperjs demo
var Casper = require('casper').Casper;
var utils = require('utils');
var links = {
'http://edition.cnn.com/': 0,
'http://www.nytimes.com/': 0,
'http://www.bbc.co.uk/': 0,
'http://www.guardian.co.uk/': 0
};
function Fantomas() {
Fantomas.super_.apply(this, arguments);
}
// Let's make our Fantomas class extending the Casper one
// please note that at this point, CHILD CLASS PROTOTYPE WILL BE OVERRIDEN
utils.inherits(Fantomas, Casper);
Fantomas.prototype.countLinks = function() {
return this.evaluate(function() {
return __utils__.findAll('a[href]').length;
});
};
Fantomas.prototype.renderJSON = function(what) {
return this.echo(JSON.stringify(what, null, ' '));
};
var fantomas = new Fantomas({
verbose: true,
logLevel: "debug"
});
fantomas.start();
Object.keys(links).forEach(function(url) {
fantomas.thenOpen(url, function() {
links[url] = this.countLinks();
});
});
fantomas.run(function() {
this.renderJSON(links).exit();
});
JavaScript
1
https://gitee.com/shentong_012/casperjsDemo.git
git@gitee.com:shentong_012/casperjsDemo.git
shentong_012
casperjsDemo
casperjsDemo
master

搜索帮助