Last active
December 11, 2015 01:59
-
-
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
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 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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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