我試圖用PhantomJS加載頁面並將其保存爲.png。但是,創建的png看起來並不像原來的那樣,並且缺少大部分正文。在線搜索中,大部分類似的問題都是因爲沒有足夠長的時間來加載頁面。但是,這還沒有解決我的問題。這是我正在運行:PhantomJS未加載動態內容
var page = require('webpage').create();
var websiteAddress = 'http://poe.ninja/standard/currency';
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.120 Safari/537.36';
//viewportSize being the actual size of the headless browser
page.viewportSize = { width: 1920, height: 1080 };
//the clipRect is the portion of the page you are taking a screenshot of
page.clipRect = { top: 0, left: 0, width: 1920, height: 1080 };
page.open(websiteAddress, function (status) {
setTimeout(function(){
page.render('output.png');
phantom.exit();
}, 5000); // 5 sec should be enough
});
我做錯了什麼或者這是一個在PhantomJS中的錯誤?
下面是它應該是什麼樣子和圖像它實際上是這樣的:
添加[page.onError](http://phantomjs.org/api/webpage/handler /on-error.html)回調來檢查是否有任何錯誤。 – Vaviloff