Commit d7458b17 d7458b17b646842ea40f5412a039019d20cbd8df by Nicolas Perriault

added metaextract sample scripts

1 parent 930f368c
1 casper = require("casper").create()
2 url = casper.cli.get 0
3 metas = []
4
5 if not url
6 casper.echo "Usage: casperjs [url]"
7 casper.exit()
8
9 casper.start url, ->
10 metas = @evaluate ->
11 metas = []
12 castarray = (arr) -> [].slice.call(arr)
13 for elem in castarray document.querySelectorAll "meta"
14 meta = {}
15 for attr in castarray elem.attributes
16 meta[attr.name] = attr.value
17 metas.push meta
18 metas
19
20 casper.run ->
21 require("utils").dump metas
22 this.exit()
1 var casper = require("casper").create()
2 , url = casper.cli.get(0)
3 , metas = [];
4
5 if (!url) {
6 casper.echo('Usage: casperjs [url]').exit();
7 }
8
9 casper.start(url, function() {
10 metas = this.evaluate(function() {
11 var metas = [];
12 [].forEach.call(document.querySelectorAll('meta'), function(elem) {
13 var meta = {};
14 [].slice.call(elem.attributes).forEach(function(attr) {
15 meta[attr.name] = attr.value;
16 });
17 metas.push(meta);
18 });
19 return metas;
20 });
21 });
22
23 casper.run(function() {
24 require("utils").dump(metas);
25 this.exit();
26 });