Skip to content

Instantly share code, notes, and snippets.

@dandrews
Last active December 11, 2015 01:59
Show Gist options
  • Save dandrews/4527460 to your computer and use it in GitHub Desktop.
Save dandrews/4527460 to your computer and use it in GitHub Desktop.
Scrape all the URLs for the individual mentors on http://www.techstars.com/program/mentors/#all, using CasperJS
var url = 'http://www.techstars.com/program/mentors/#all';
var casper = require('casper').create({
// verbose: true,
// logLevel: 'debug',
pageSettings: {
loadImages: false,
loadPlugins: false
}
});
casper.on('error', function(msg, backtrace) {
this.echo("=========================");
this.echo("ERROR:");
this.echo(msg);
this.echo(backtrace);
this.echo("=========================");
});
casper.on("page.error", function(msg, backtrace) {
this.echo("=========================");
this.echo("PAGE.ERROR:");
this.echo(msg);
this.echo(backtrace);
this.echo("=========================");
});
var mentors = []
function getMentors() {
var mentors = document.querySelectorAll('li.mentor');
return Array.prototype.map.call(mentors, function(e) {
return e.getElementsByTagName('a')[0].getAttribute('href')
});
}
casper.start( url );
casper.then(function() {
mentors = this.evaluate(getMentors);
});
casper.then( function() {
for ( i = 0 ; i < mentors.length ; i++ )
{
this.echo( mentors[i] );
}
});
casper.run(function() {
this.exit();
});
@dandrews
Copy link
Author

Scrape all the URLs for the individual mentors on http://www.techstars.com/program/mentors/#all, using CasperJS

run on command line like:
casperjs mentor_urls.js 2>&1 | tee mentor_urls.txt

webscraping #casperjs #phantomjs #javascript

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