Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rendering a javascript webpage page with phantomjs

I am trying to render a a javascript evaluated source code from a website using phantomjs. But every time I try i only get the source code as is (similar to view source from the browser). What I actually want is the javascript evaluated code (what we see from inspect element from google chrome browser). My code looks like this:

var page = require('webpage').create();
page.open('http://www.google.com/', function (s) {
    console.log(page.content);
    phantom.exit();
});

Am I doing something wrong here?

like image 553
Trancey Avatar asked Feb 28 '13 16:02

Trancey


1 Answers

This did the trick for me:

window.setTimeout(function () {
        page.render(output);
        phantom.exit();
    }, 1000);
like image 97
James Gentes Avatar answered Sep 16 '22 16:09

James Gentes