Skip to content

Instantly share code, notes, and snippets.

@dandrews
Created April 11, 2013 00:26
Show Gist options
  • Save dandrews/5359666 to your computer and use it in GitHub Desktop.
Save dandrews/5359666 to your computer and use it in GitHub Desktop.
Scrape Market tags from http://angel.co/markets using CasperJS. This script is a basic example, and so it doesn't click any of the dropdown arrows or the 'More' buttons, so it only returns the top-level tags.
var utils = require('utils');
var markets_url = 'https://angel.co/markets';
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 markets = []
function getMarkets() {
markets = document.querySelectorAll('div.item-tag');
return Array.prototype.map.call(markets, function(e) {
return e.innerText
});
}
casper.start( markets_url );
casper.then(function() {
markets = this.evaluate(getMarkets);
});
casper.then( function() {
this.each(markets, function(self, market) {
this.echo( market );
})
});
casper.run(function() {
this.exit();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment