Last active
May 16, 2016 09:15
-
-
Save ianchanning/fbdb99a6bdfa61d34ab283a31335af3e to your computer and use it in GitHub Desktop.
Bowie discography scraping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var links = []; | |
var casper = require('casper').create(); | |
function getLinks() { | |
var links = document.querySelectorAll('div#mw-content-text table.wikitable tbody tr td i b a'); | |
return Array.prototype.map.call(links, function(e) { | |
return 'https://en.wikipedia.org' + e.getAttribute('href'); | |
}); | |
} | |
casper.start('https://en.wikipedia.org/wiki/David_Bowie_discography'); | |
casper.then(function() { | |
// aggregate results for the 'casperjs' search | |
links = this.evaluate(getLinks); | |
casper.each(links, function (self, link) { | |
self.thenOpen(link, function () { | |
this.echo(this.getTitle() + " - " + link); | |
}); | |
}); | |
}); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment