Skip to content

Instantly share code, notes, and snippets.

@blessdyb
Created November 14, 2013 13:14
Show Gist options
  • Save blessdyb/7466569 to your computer and use it in GitHub Desktop.
Save blessdyb/7466569 to your computer and use it in GitHub Desktop.
Use Casper to scrap web page.
var utils = require('utils');
var casper = require('casper').create({
verbose: true,
logLevel: 'error',
pageSettings: {
loadImages: false,
loadPlugins: false,
userAgent: 'Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36'
}
});
casper.start('http://app.baidu.com/appweb/search?w=qq&cid=0&lcid=0&ps=100&pn=3', function() {
var img = this.evaluate(function() {
var images = document.querySelectorAll('.search-list li img');
var imageSrcList = [];
for (var i = 0; i < images.length; i++) {
imageSrcList.push(images[i].getAttribute('src'));
}
return imageSrcList;
});
utils.dump(img);
});
casper.run(function() {
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment