PhantomJs返回未定义的page.title
从PhantomJs控制台input
var page = require('webpage').create();page.open('http://phantomjs.org', function (status) {console.log(page.title);});
它不打印页面标题,但只是未定义
为什么?
首先require("webpage")
不是phantomJS的模块,所以这是不正确的。
尝试使用是在文档中概述:
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 ; })