Skip to content

Instantly share code, notes, and snippets.

@j67678
Created November 3, 2013 04:11
Show Gist options
  • Save j67678/7286637 to your computer and use it in GitHub Desktop.
Save j67678/7286637 to your computer and use it in GitHub Desktop.
casperjs capture
var casper = require("casper").create({
pageSettings: {
loadImages: false,
loadPlugins: false
}
}),
utils = require('utils');
casper.start('http://opac.hkc.edu.cn/opac/newpub/cls');
function findRecords() {
var elements = __utils__.getElementsByXPath('//table[@class="resultTable"]/tbody/tr');
return Array.prototype.map.call(elements, function(element) {
var record = new Object;
record.title = element.querySelector('.bookmetaTitle a').innerText.trim();
record.link = element.querySelector('.bookmetaTitle a').href;
record.author = element.querySelector('div.bookmeta div:nth-child(2) a').innerText.trim();
return record;
});
}
casper.withFrame('categoryRight', function() {
casper.then(function() {
var records = this.evaluate(findRecords);
//this.echo(JSON.stringify(records));
utils.dump(records);
});
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment