user310291 user310291 - 3 months ago 30
Node.js Question

PhantomJs returns undefined for page.title

From PhantomJs console I typed

var page = require('webpage').create();page.open('http://phantomjs.org', function (status) {console.log(page.title);});


It doesn't print the page title but only undefined

Why ?

Answer

Firstly require("webpage") is not phantomJS' module, so that's incorrect.

Try use is as outlined in the documentation :

https://github.com/amir20/phantomjs-node

var phantom = require('phantom');

var sitepage = null;
var phInstance = null;
phantom.create()
    .then(instance => {
        phInstance = instance;
        return instance.createPage();
    })
    .then(page => {
        sitepage = page;
        page.open('http://phantomjs.org', function(){
            console.log("Title : " + page.title);
        });
       return ;
    })
Comments