phantomjs 长图截屏

var page = require('webpage').create();
var url = 'http://cardloan9.hateblo.jp/';
 page.settings = {
       userAgent:"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.109 Safari/537.36",
  	  javascriptEnabled: true,
      loadImages: true
};
page.open(url, function (status) 
{
    if (status != "success") 
    {
        console.log('FAIL to load the address');
        phantom.exit();
    }
    
   var scrollheight= page.evaluate(function()
    {
        //此函数在目标页面执行的,上下文环境非本phantomjs,所以不能用到这个js中其他变量
        
         return  document.body.scrollHeight;
    });
    
    window.setTimeout(function () 
    {
    
	   
		  console.log( 'scrollheight:'+ scrollheight);  
page.viewportSize = {width:1000,height:scrollheight};
        page.render("json2form.png");
        phantom.exit();
    },60000);    

});

  

posted @ 2017-07-31 11:46  公众号python学习开发  阅读(345)  评论(0编辑  收藏  举报