java phantomjs 截图_phantomjs 截图
phantomjs 截圖,多個setTimeout是為了讓頁面盡量加載完整
/**截圖test.js**/
var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 600 };
page.open('http://www.2345.com/', function(status) {
var bb= page.evaluate(function(){
// window.scrollTo(0,10000);//滾動到底部
window.document.body.scrollTop = document.body.scrollHeight;
return window.document;
});
// 按照實際頁面的高度,設(shè)定渲染的寬高
page.clipRect = {top:0,left: 0,width:bb.width,height: bb.height+300};
window.setTimeout(function () {
console.log("start開始截圖");
window.document.body.scrollTop = document.body.scrollHeight/2;
window.setTimeout(function(){
window.document.body.scrollTop = document.body.scrollHeight/4;
window.setTimeout(function(){
page.render('www.2345.com.png');
// console.log(page.content);
phantom.exit();
},1500);
},1500);
}, 1500);
});
運行:在命令行中切換到phantomjs-2.0.0-windows\bin 路徑下,這個路徑下有phantomjs.exe;
然后執(zhí)行phantomjs.exe --output-encoding=gb2312 test.js
總結(jié)
以上是生活随笔為你收集整理的java phantomjs 截图_phantomjs 截图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 查找单链表的中间节点,要求只能遍历一次链
- 下一篇: opengl 深度详解_一步步学Open