简体   繁体   中英

How can I change the screen resolution of PhantomJS?

In any way I can not find a question concerning change of the sanction of the screen. There will always be 1024x768 . Changing the viewportSize does not change the screen resolution, by itself. I checked the resolution here: link

This is for node:

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

page.onInitialized = function () {
    page.evaluate(function () {
        window.screen = {width: 1600, height: 900, availWidth: 1600, availHeight: 900};
    });
};

page.open('http://browserspy.dk/screen.php');
page.onLoadFinished = function () {
    page.render('ScreenShot' + '.png');
    phantom.exit();
}

Can anyone remake for the python?

Try using viewportSize. Refer this link ViewPortSize

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM