我有幾個客戶端橫幅(例如 - 寬度160像素和高度600像素),但是當我嘗試截取屏幕截圖時,我看到一個結果作爲圖像400x600與白色背景(或黑色當結果文件是JPEG時)和橫幅在左側(約160x600)。我無法硬編碼viewPortSize因爲所有橫幅都不同。 是否有可能動態設置viewPortSize或其他東西有像橫幅完全一樣的結果圖片?phantomjs截圖並不縮放到頁面內容
const page = require('webpage').create();
const system = require('system');
/**
* FIRST ARG - name of this runner
* SECOND ARG - input html file
* THIRD ARG - destination
*/
if (system.args.length !== 3) {
console.log('Usage: phantomRunner.js [inputFile] [destination]');
phantom.exit();
}
const inputFile = system.args [1];
const outputPath = system.args [2];
page.open(inputFile, function (status) {
if (status !== 'success') {
phantom.exit(1);
} else {
page.render(outputPath);
phantom.exit();
}
});
我已經嘗試將viewPortSize減小到10x10,但它沒有幫助。
編輯 我發現它不可能改變瀏覽器的寬度大小低於360及其問題。
我想在截圖的時候這些橫幅還沒有呈現。你需要在'page.render'之前設置一些延遲 – MysterX
@MysterX nope ...它的加載和我看到的廣告,添加1秒的延遲,但結果相同 – bearhunterUA