added metaextract sample scripts
Showing
4 changed files
with
50 additions
and
2 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 | }); |
... | @@ -13,7 +13,7 @@ var casper = require('casper').create({ | ... | @@ -13,7 +13,7 @@ var casper = require('casper').create({ |
13 | // Overriding Casper.open to prefix all test urls | 13 | // Overriding Casper.open to prefix all test urls |
14 | casper.setFilter('open.location', function(location) { | 14 | casper.setFilter('open.location', function(location) { |
15 | if (!/^http/.test(location)) { | 15 | if (!/^http/.test(location)) { |
16 | return 'file://' + phantom.casperPath + '/' + location; | 16 | return f('file://%s/%s', phantom.casperPath, location); |
17 | } | 17 | } |
18 | return location; | 18 | return location; |
19 | }); | 19 | }); | ... | ... |
-
Please register or sign in to post a comment