Commit d908c1ab d908c1ab44901e7224167895b941c58cadc2b7f2 by Nicolas Perriault

added metaextract sample scripts

1 parent 930f368c
1 Subproject commit 50c9d3f003479ee6b62249a5ad33fa3648e9daa9 1 Subproject commit 2029165d028c53aa9223e75d2505dd3b8a9002a9
......
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 });
...@@ -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 });
......