Quantcast
Channel: 万维网黑客 » phantomjs
Viewing all articles
Browse latest Browse all 10

phantomjs 截取腾讯首页导航条生成图片并保存到本地

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

page.onConsoleMessage = function(msg) {
    page.clipRect = JSON.parse(msg);
    page.render("qq.png");
};

page.open('http://www.qq.com/',function(status){
    if(status === 'success'){
        page.includeJs('http://code.jquery.com/jquery-1.10.2.min.js',function(){
            page.evaluate(function() {
                var offset = $('#mainnav').offset(),
                    left = offset.left,
                    top = offset.top;

                var width = $('#mainnav').outerWidth(),
                    height = $('#mainnav').outerHeight();

                console.log(JSON.stringify({
                    left: left,
                    top: top,
                    width: width,
                    height: height
                }));
            });
            phantom.exit();
        });
    }
});

 


Viewing all articles
Browse latest Browse all 10

Trending Articles