var page = require('webpage').create();
page.onConsoleMessage = function (msg) {
console.log('Inner log: ' + msg);
};
var url = "http://www.w3.org/TR/CSS21/propidx.html";
page.open(url, function() {
console.log("status ",status);
var props = page.evaluate(function() {
var x = document.getElementsByClassName('xref');
for (var i=0;i<x.length;++i) {
console.log(x[i].innerText);
}
...
输出:
❯ phantomjs css21_parser.js
2013-03-17 03:27:01.737 phantomjs[95167:707] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
status
Inner log: 'azimuth'
Inner log: 'background-attachment'
Inner log: 'background-color'
Inner log: 'background-image'
Inner log: 'background-position'
Inner log: 'background-repeat'
....
基本上,示例和API文档声明应该针对“成功”检查成功,但在这种情况下,它似乎是空字符串。
答案 0 :(得分:2)
我不完全确定这是否可以解决您的问题,但您是否尝试将字符串加入,而不是逗号分开?
console.log("status " + status);
编辑:
我刚刚注意到你的问题。你没有在回调函数中传递status
变量。
您的回调函数应如下所示:
page.open(url, function(status) {