主要是是通过对浏览器的可视化范围进行扩大来实现异步加载网页的截图。
var page = require('webpage').create();
var system = require('system');
if (system.args.length != 3) {
console.log('参数不正确!');
} else {
var argUrl=system.args[1];
var argTime=system.args[2];
page.viewportSize = { width: 1680, height: 1000 };
page.open(argUrl, function(status) {
var htmlHeight=page.evaluate(function(){
var h= document.body.offsetHeight;
return h
});
var htmlWidth=page.evaluate(function(){
var w= document.body.offsetWidth;
return w;
});
console.log("htmlHeight:"+htmlHeight+" width:"+htmlWidth);
page.viewportSize = { width: htmlWidth, height: htmlHeight };
window.setTimeout(function(){
page.render("E:/a.png");
phantom.exit();
},argTime);
}
});
}