panda_Missaka
panda_Missaka

Reputation: 39

how use phantomjs screenshot the whole page

I use phantomjs to screenshot a page,but can't screenshot buttom of the page.

 var height = page.evaluate(function()
 {
   window.document.body.scrollTop = document.body.scrollHeight;                                     
   }        
 );

value of the height is 33943,but the real value of scrollHeight is 44135. how can I load the whole page?

the snapshot img

the page

Upvotes: 2

Views: 2381

Answers (2)

jessireedev
jessireedev

Reputation: 99

I managed to took a screenshot of the whole page by setting the page property.

For example:

var width = 1024, height = 768;
page.property("viewportSize", {'width': width, 'height': height});

The one on the docs page.viewportSize = { width: 1024, height: 768 }; might not be updated because it returned the warning :

warn: Using page.viewportSize = ...; is not supported. Use page.property('viewportSize', ...) instead. See the README file for more examples of page#property.

Upvotes: 1

Raptor
Raptor

Reputation: 54212

You can snapshot your page by:

var WebPage = require('webpage');
page = WebPage.create();
page.open('http://www.example.com');
page.onLoadFinished = function() {
   page.render('screenshot.png');
   phantom.exit();
}

Not sure why you need to calculate the height of your page.

Upvotes: 1

Related Questions