Created
November 3, 2013 04:11
-
-
Save j67678/7286637 to your computer and use it in GitHub Desktop.
casperjs capture
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 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