Skip to content

Instantly share code, notes, and snippets.

@n1k0
Created January 21, 2012 07:02
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save n1k0/1651844 to your computer and use it in GitHub Desktop.
Save n1k0/1651844 to your computer and use it in GitHub Desktop.
CasperJS script to extract meta informations
var casper = require("casper").create()
, url = casper.cli.get(0)
, metas = [];
if (!url) {
casper.echo('Usage: casperjs [url]').exit();
}
casper.on('remote.message', function(msg) {
console.log(msg);
});
casper.start(url, function() {
metas = this.evaluate(function() {
var metas = [];
[].forEach.call(document.querySelectorAll('meta'), function(elem) {
var meta = {};
[].slice.call(elem.attributes).forEach(function(attr) {
meta[attr.name] = attr.value;
});
metas.push(meta);
});
return metas;
});
});
casper.run(function() {
require("utils").dump(metas);
this.exit();
});
@n1k0
Copy link
Author

n1k0 commented Jan 21, 2012

Sample output:

$ casperjs samples/metaextract.js http://akei.com
[
    {
        "content": "text/html; charset=utf-8",
        "http-equiv": "Content-Type"
    },
    {
        "content": "index, follow",
        "name": "robots"
    },
    {
        "content": "-CBaKTlXHwyFTqJRYEur9pB9OEkG7BXsHO0SNDN1Cg0",
        "name": "google-site-verification"
    },
    {
        "content": "akei, informatique, internet, conseil, audit, expertise, web, formation, développement, lamp, mysql, php, symfony, python, django, framework, agile, scrup, xp",
        "name": "keywords"
    },
    {
        "content": "Akei accompagne vos projets Web au travers son offre de conseil, de formation et de développement.",
        "name": "description"
    }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment