【问题标题】:Phantomjs only renders blank pictures from local html filesPhantomjs 只渲染本地 html 文件中的空白图片
【发布时间】:2017-09-29 14:23:46
【问题描述】:

我猜这个任务很简单。我想从本地 html 文件生成屏幕截图(png - 文件)。

我的“概念证明”看起来像这样...... 这些文件位于 Windows 10 机器上的本地文件夹中:c:\temp\

这将是一个非常基本的 html 文件 - 只是为了确保没有复杂的东西干扰(​​文件名为:a.html):

<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- otherwise format might be broken when opening from local source -->
        <title>Savills Charts</title>
    </head>
<body>
<h1>HalloBallo</h1>
<p>My baby baby, Balla Balla!</p>

</body>
</html>

调用 phantomjs 的脚本取自这里:http://www.cameronjtinker.com/post/2011/09/26/Take-Screenshot-of-all-HTML-documents-in-a-folder-using-PhantomJS.aspx 在我的工作中,我认为我自己的脚本是问题,但它看起来不像。

var page = require('webpage').create();
  page.open("file:///c:/temp/a.html", function() {   
    page.render('C:/temp/screenshot.png');  
  phantom.exit();
});

phantomjs 只生成黑色的 .png 文件。 如果我将源从本地的东西切换到网络上的东西

page.open("file:///c:/temp/a.html"

到

page.open("http://spon.de"

然后一切正常.... 我迷路了... 我能做什么?

韩国, 马丁

【问题讨论】:

    标签: javascript html phantomjs


    【解决方案1】:

    也许有一天有人会像我一样绊倒。 因此,我想澄清。问题是,(与网络浏览器相比)phantomjs 默认不设置任何颜色。因此,在给出的网站(参见示例代码)中,phantomjs 只是在黑色背景上呈现黑色文字。

    如果你给 body 一个背景色,那么你会看到黑色字体。

    所以 - 它解决了。

    马丁

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-04
      • 2018-03-15
      • 2015-11-03
      • 2019-12-24
      相关资源
      最近更新 更多