Skip to content

Instantly share code, notes, and snippets.

@juanramon
Created March 27, 2013 15:36
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 juanramon/5255171 to your computer and use it in GitHub Desktop.
Save juanramon/5255171 to your computer and use it in GitHub Desktop.
/*jshint strict:false*/
/*global CasperError, console, phantom, require*/
var links = [];
var casper = require("casper").create();
casper.defaultWaitForTimeout = 20000;
function getLinks() {
var links = document.querySelectorAll("a[name='productview']");
return Array.prototype.map.call(links, function(e) {
return ('http://www.misterspex.es').concat(e.getAttribute("href")).replace(/\s+/g, '');;
});
}
var processPage = function() {
links = links.concat(this.evaluate(getLinks));
if (this.exists(".next a")) {
this.thenClick(".next a").then(function() {
url = this.getCurrentUrl();
casper.then(processPage);
});
}
}
var processAd = function() {
this.each(links, function(self, link) {
this.thenOpen(link, function() {
this.echo(link + "," + this.getHTML('#Brand dt') + "," + this.getHTML('#Brand dd') + ',"' + this.getHTML('#AddDirect .price') + '"');
});
});
}
casper.start("http://www.misterspex.es/gafas-de-sol/");
// process list
casper.then(processPage);
// process each ad
casper.then(processAd);
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment