Skip to content

Instantly share code, notes, and snippets.

@adnasa
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adnasa/a10b681ef27096e6f975 to your computer and use it in GitHub Desktop.
Save adnasa/a10b681ef27096e6f975 to your computer and use it in GitHub Desktop.
quick and dirty hack to get the discography list from an artist in wikipedia :D
var _ = require('underscore')._;
var casper = require('casper').create({
clientScripts: [
'bower_components/jquery/dist/jquery.min.js',
'bower_components/underscore/underscore.js'
],
verbose: true,
logLevel: 'debug'
});
casper.start('http://en.wikipedia.org/wiki/Q-Tip_(musician)', function() {
var discographyList = this.evaluate(function() {
var k = /(d|D)(iscography)/g; // quick and dirty
var contentText = $('#mw-content-text');
var headlines = $('h2', contentText);
var matchingHeadline = _.find(headlines, function(headline) {
return headline.innerHTML.match(k);
});
var table = null;
if (matchingHeadline) {
matchingHeadline = $(matchingHeadline);
var next = matchingHeadline.next();
while (next) {
if (next[0].nodeName.toLowerCase() !== 'ul') {
next = next.next();
} else {
table = next;
next = null;
}
}
}
var discos = [];
if (table) {
var childElements = $('li', table);
_.each(childElements, function(element) {
discos.push($(element).text());
});
}
return discos;
});
utils.dump(discographyList);
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment