PhantomJs不会调整窗口大小

编程入门 行业动态 更新时间:2024-10-11 07:33:23
本文介绍了PhantomJs不会调整窗口大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用以下代码: var width = 1024; var height = 768;

I am using this code: var width = 1024; var height = 768;

和page.viewportSize = {width:width,height:height};我在page.open之前使用.但这是行不通的. 您可以在这里查看我的另一个问题的完整代码- 在PhantomJS中建立引荐标头是不能的不起作用

and page.viewportSize = {width: width, height: height}; im using before page.open . But this doesn't work. The full code you can watch in my another question right here - Faking the Referer Header in PhantomJS is doesn't work

下面是代码:

var width = 1024; var height = 768; var page = require('webpage').create(); //referal massive var reff = ["www.facebook/messages/t/","google","youtube","twitter/"]; //random massive var randreff = Math.floor(Math.random() * (reff.length)); //reffer page.customHeaders = { "Referer": (reff[randreff]) }; //console refer console.log(reff[randreff]); var urls = ['test/','test/2017/02/blog-post.html','test/']; var i = 0; function OpenPage(){ setTimeout(function(){ page.open(urls[i], function(status) { if (status == 'success') { page.viewportSize = {width: width, height: height}; page.render('example' + i + '.png'); } i++; if(i <= urls.length - 1){ OpenPage(); }else{ phantom.exit(); } }); },5000); } OpenPage();

  • 解决方案无效,引荐无效=(
  • 推荐答案

    page.render()呈现整个页面,而不考虑视口大小,这是正常的行为...您需要的是page.clipRect() ...类似于:

    page.render() renders whole page regardless of viewport size, it's normal behaviour ... what you need is page.clipRect()... something like:

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

    以上内容应在page.open()之前定义-告诉页面以类似于窗口具有给定大小的方式呈现

    The above should be defined before page.open() - tells a page to render the way like the window would be of given size

    要渲染给定尺寸的图像,您需要:

    To render image of given size, you need to:

    page.clipRect = { top: 0, left: 0, height: viewportSize.height, width: viewportSize.width }; page.render(...);

更多推荐

PhantomJs不会调整窗口大小

本文发布于:2023-07-09 20:58:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1088187.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:大小   窗口   PhantomJs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!