var page = require('webpage').create(), loadInProgress = false, fs = require('fs');
var htmlFiles = new Array();
console.log(fs.workingDirectory);
var curdir = fs.list(fs.workingDirectory);
// loop through files and folders
for(var i = 0; i< curdir.length; i++)
{
var fullpath = fs.workingDirectory + fs.separator + curdir[i];
// check if item is a file
if(fs.isFile(fullpath))
{
// check that file is html
if(fullpath.indexOf('.html') != -1)
{
// show full path of file
console.log('File path: ' + fullpath);
htmlFiles.push(fullpath);
}
}
}
console.log('Number of Html Files: ' + htmlFiles.length);
// output pages as PNG
var pageindex = 0;
var interval = setInterval(function() {
if (!loadInProgress && pageindex < htmlFiles.length) {
console.log("image " + (pageindex + 1));
page.open(htmlFiles[pageindex]);
}
if (pageindex == htmlFiles.length) {
console.log("image render complete!");
phantom.exit();
}
}, 250);
page.onLoadStarted = function() {
loadInProgress = true;
console.log('page ' + (pageindex + 1) + ' load started');
};
page.onLoadFinished = function() {
loadInProgress = false;
page.render("images/output" + (pageindex + 1) + ".png");
console.log('page ' + (pageindex + 1) + ' load finished');
pageindex++;
}
Nadzieja to helps. Aby uzyskać więcej informacji na temat wywołań FileSystem, sprawdź tę stronę: http://phantomjs.org/api/fs/
Ponadto chciałem dodać, że wierzę, że funkcje FileSystem są dostępne tylko w PhantomJS 1.3 lub nowszym. Pamiętaj, aby uruchomić wersję latest. Używałem PyPhantomJS dla Windows, ale jestem pewien, że to będzie działało bez problemu także w innych systemach.
Jakoś mam tylko puste 'PNG's z twoim skryptem. Dodanie 'console.log (page.content);' w 'page.onLoadFinished' zwraca'
'nie ma znaczenia, czy prawdziwa treść HTML jest ... Jakieś sugestie? Phantomjs v1.9.2 – AvLCzy jesteś pewny, że Twoje strony ładują się całkowicie, zanim spróbujesz zrobić migawki? –
Sprawdziłem także "status". Zobacz moje pytanie: http://stackoverflow.com/questions/19939046/phantomjs-fails-to-open-local-file – AvL