PhantomJs为page.title返回undefined

时间:2016-08-08 14:53:34

标签: node.js phantomjs

从PhantomJs控制台我输入

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

它不会打印页面标题,只会打印未定义的

为什么?

1 个答案:

答案 0 :(得分:3)

首先require("webpage")不是幻影'模块,这是不正确的。

尝试使用如文档中所述:

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 ;
    })