gpt4 book ai didi

viewportSize 似乎不适用于 PhantomJS

转载 作者:行者123 更新时间:2023-12-04 02:02:53 24 4
gpt4 key购买 nike

这个 PhantomJS 脚本的输出不应该是 240x320 像素吗?我得到了一个大的、默认大小的图像。 clipRect() 似乎会呈现正确大小的图像,但我需要页面的响应内容来反射(reflect)实际的浏览器窗口大小。

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);
}

});

最佳答案

这有效!!
issue 的 github 页面上找到了片段.它强制'body'元素到页面viewportSize:

var width = 1024;
var height = 768;
var webpage = require('webpage');

page = webpage.create();
page.viewportSize = {width: width, height: height};
page.open('http://harness.io', function(status) {
console.log(status);
page.evaluate(function(w, h) {
document.body.style.width = w + "px";
document.body.style.height = h + "px";
}, width, height);
page.clipRect = {top: 0, left: 0, width: width, height: height};
page.render('/tmp/test.png');
phantom.exit();
});

关于viewportSize 似乎不适用于 PhantomJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com