Created
March 27, 2013 15:36
-
-
Save juanramon/5255171 to your computer and use it in GitHub Desktop.
This file contains 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
/*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