這個任務很簡單,我猜。我想從本地html文件中生成屏幕截圖(png - 文件)。Phantomjs只渲染來自本地html文件的空白圖片
我的「概念驗證」看起來像這樣... 該文件位於在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( 「文件:/// C:/temp/a.html」
到
page.open( 「http://spon.de」
然後一切工作正常.... 我迷路了...... 我該怎麼辦?
KR, 馬丁