Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PhantomJS屏幕截图始终为空_Javascript_Phantomjs - Fatal编程技术网

Javascript PhantomJS屏幕截图始终为空

Javascript PhantomJS屏幕截图始终为空,javascript,phantomjs,Javascript,Phantomjs,我已经安装了PhantomJS,来自的示例脚本运行良好 我正在努力工作: 但我一直得到的只是一个582Kb的空白github.png文件 有什么想法吗?您可能需要等待页面实际加载和呈现。尝试添加超时: var page = require('webpage').create(); page.open('http://github.com/', function() { setTimeout(function() { page.render('github.png'); p

我已经安装了PhantomJS,来自的示例脚本运行良好

我正在努力工作:

但我一直得到的只是一个582Kb的空白github.png文件


有什么想法吗?

您可能需要等待页面实际加载和呈现。尝试添加超时:

var page = require('webpage').create();
page.open('http://github.com/', function() {
  setTimeout(function() {
     page.render('github.png');
     phantom.exit();
  }, 500);
});

@ced-b的建议是明智的,但我认为您的问题不会通过超时解决,因为真正的问题很可能是SSL/TLS。GitHub是一个HTTPS网站。因此,如果您想获得屏幕截图,您可能需要在运行PhantomJS脚本时添加
--ignoresslerrors=true
选项。默认情况下,您应该会收到一个窄屏幕截图,但您当然可以设置一个更大的视口:

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

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

page.open('https://github.com/', function () {
  page.render('github.png');
  phantom.exit();
});

与此库有相同的问题:

设置sslCertificatesPath('any')修复了该问题

new Screenshot('https://somerandomsite.com/')
  .width(320)
  .height(320)
  .sslCertificatesPath('any')
  .capture()
  .then(img => {
    // do stuff with img
  })

你能把png文件上传到什么地方吗?如果它那么大,它可能不是空的。可能URL需要
https://github.com/
,因为GitHub现在可以安全地提供服务。为了避免这种猜测,我刚刚用最新的PhantomJS尝试了这段代码,它对我来说很好。Liam,你的PhantomJS版本是什么?对于回复的长时间延迟,我深表歉意:(phihag:你说得对,这是一个不可见的400x300px png文件。这是一个副本:。Andy:我尝试了https,但仍然生成相同的文件。Vaviloff:version 2.1.1Badacadabra:尝试添加--ignore ssl errors=true,由于尺寸较大,仍然生成相同的png。此脚本在我的计算机上运行良好。)(我使用的是相同的PhantomJS版本)。您的环境是什么?
new Screenshot('https://somerandomsite.com/')
  .width(320)
  .height(320)
  .sslCertificatesPath('any')
  .capture()
  .then(img => {
    // do stuff with img
  })