【发布时间】: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