viewportSize似乎不适用于PhantomJS [英] viewportSize seems not to work with PhantomJS

查看:101
本文介绍了viewportSize似乎不适用于PhantomJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此PhantomJS脚本的输出不应该是240x320像素吗?我得到一个大的,默认大小的图像. clipRect()似乎可以渲染正确大小的图像,但是我需要页面的响应内容来反映实际的浏览器窗口大小.

Shouldn't the output from this PhantomJS script be 240x320 pixels? I'm getting a large, default-sized image. clipRect() would seem to render the correct size image, but I need the responsive content of the page to reflect the actual browser window size.

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

page.viewportSize = { width: 240, height: 320 };  

page.open('http://cnn.com', function (status) {

    if (status !== 'success') {
        console.log('Unable to load the address!');
    } else {
        window.setTimeout(function () {
            page.render('default.png');
            phantom.exit();
        }, 200);
    }

});

推荐答案

这是一个已知问题,但我找到了解决方法:

This is a known issue but I found a workaround:

  1. 将页面加载到任意大小的iframe中.
  2. 渲染截取到iframe矩形的屏幕截图.

在此存储库中有执行此操作的代码: https://github.com/jbeuckm/Splasher

There is code to do it in this repository: https://github.com/jbeuckm/Splasher

这篇关于viewportSize似乎不适用于PhantomJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆