我安装了 PhantomJS 和来自 the official Phantom website 的示例脚本工作正常。
我正在尝试获取 this screenshot example上类:
var page = require('webpage').create();
page.open('http://github.com/', function() {
page.render('github.png');
phantom.exit();
});
但我得到的只是一个重达 582Kb 的空白 github.png 文件
有什么想法吗?
最佳答案
@ced-b 的建议是明智的,但我认为使用超时不会解决您的问题,因为真正的问题很可能与 SSL/TLS 有关。 GitHub 是一个 HTTPS 网站。因此,如果您想获取屏幕截图,您可能需要在运行 PhantomJS 脚本时添加 --ignore-ssl-errors=true
选项。默认情况下,您应该收到一个狭窄的屏幕截图,但您当然可以设置更大的视口(viewport):
var page = require('webpage').create();
page.viewportSize = {
width: 1920,
height: 1080
};
page.open('https://github.com/', function () {
page.render('github.png');
phantom.exit();
});
关于javascript - PhantomJS 截图总是空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45200869/