Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print html source to console with phantomjs

I just downloaed and installed phantomjs on my machine. I copy and pasted the following script into a file called hello.js:

var page = require('webpage').create();
var url = 'https://www.google.com'

page.onLoadStarted = function () {
    console.log('Start loading...');
};

page.onLoadFinished = function (status) {
    console.log('Loading finished.');
phantom.exit();
};

page.open(url);

I'd like to print the complete html source (in this case from the google page) to a file or to the console. How do I do this?

like image 866
toom Avatar asked Sep 16 '12 21:09

toom


1 Answers

Spent some time to read the documentation, it should be obvious afterwards.

var page = require('webpage').create();
page.open('http://google.com', function () {
    console.log(page.content);
    phantom.exit();
});
like image 171
Ariya Hidayat Avatar answered Sep 20 '22 22:09

Ariya Hidayat