added metaextract sample scripts
Showing
2 changed files
with
48 additions
and
0 deletions
samples/metaextract.coffee
0 → 100644
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() |
samples/metaextract.js
0 → 100644
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 | }); |
-
Please register or sign in to post a comment