2016-11-09 44 views
0

我有這個腳本截屏與PhantomJS:page.clipRect導致page.render()掛

var page = require('webpage').create(); 
    page.open('https://github.com', function() { 
    page.viewportSize = { width: 320, height: 600 }; 
    page.render('e:\\Screenshots\\test.png'); 
    phantom.exit(); 

它工作正常,但我想設置的視口的高度,因爲它是目前整個頁面高度。

文檔說使用page.clipRect:http://phantomjs.org/screen-capture.html

但是,下面的代碼不能正常工作,它只是掛起,從不截圖:

var page = require('webpage').create(); 
    page.open('https://github.com', function() { 
    page.viewportSize = { width: 320, height: 600 }; 
    page.clipRect = { top: 0, left: 0, width: 320 height: 600 }; 
    page.render('e:\\Screenshots\\test.png'); 
    phantom.exit(); 

我沒有得到任何錯誤,只是沒有發生並輸入攤位。

任何想法是怎麼回事?

回答

0

只是一個普通的老錯字:

page.clipRect = { top: 0, left: 0, width: 320 height: 600 }; 

應該

page.clipRect = { top: 0, left: 0, width: 320, height: 600 }; 
              ^

但爲什麼會PhantomJS只是掛在那裏默默?在v2中有一個錯誤,因爲它不會顯示錯誤,所以現在我使用v1.9.8來查找語法錯誤。

+0

啊啊謝謝,不敢相信我沒注意到。 1.9.8的好消息,我從現在開始也會這樣做。 – Guerrilla