版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
phantomjs实现
具体步骤如下
1. 下载对应系统版本的phantomjs到本地,例如我的phantomjs-2.1.1-macosx
2.编写爬取逻辑代码phantomjs.js:
var page = require('webpage').create();
page.settings.userAgent = 'SpecialAgent';
page.settings.javascriptEnabled = true;
phantom.cutputEncoding = 'gbk';
page.open("https://www.jianshu.com", function(status) {
if(status === "success") {
console.log("Page success");
page.render("jianshu.png");
} else {
console.log("Page failed to load.");
};
phantom.exit();
});
3,执行
/Users/***/Desktop/phantomjs-2.1.1-macosx/bin/phantomjs phantomjs.js
slimerjs实现
具体步骤如下
1. 安装步骤命令:
npm install slimerjs
npm install node-slimerjs\n
./node_modules/.bin/slimerjs -v
2.编写爬取逻辑代码slimerjs.js:
var webpage = require('webpage').create();
webpage
.open('https://davidwalsh.name')
.then(function(){
webpage.viewportSize = {
width: 1042, height: 2048 };
webpage.render('dwb.png', {
onlyViewport: true });
slimer.exit()
});
3. 执行命令
./node_modules/.bin/slimerjs src/slimerjs.js