PhantomJS 抓取截屏

var page = require('webpage').create();

//属性指定浏览器视口的大小,即网页加载的初始浏览器窗口大小。

page.viewportSize = { width: 800, height: 600 };

var url = 'http://www.baidu.com'

//用来指定网页截图的大小

//page.clipRect = { top: 0, left: 0, width: 800, height: 600 }; 

//设置 userAgent

page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';

//添加一个cookie

var st = page.addCookie({

    'name':'cookie-name',   //参数必选

    'value':'cookie-value', //参数必选

    'domain':'.baidu.com',

    'path':'/',             //参数必选

    'httponly':true,

});

page.open(url,function(status){

    console.log('status'+status)

    if (status === 'success'){

        //延迟10s 等待ajax请求完成

        window.setTimeout(function(){

            page.render('example.png');

            phantom.exit();

        },10000)

    }

})


在线交流