0
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 文档说明应根据“成功”检查成功,但在这种情况下,它似乎是空字符串。

4

1 回答 1

2

我不完全确定这是否会解决您的问题,但是您是否尝试将字符串连接在一起,而不是逗号分隔?

console.log("status " + status);

编辑:

我刚刚注意到你的问题。您没有status在回调中传递变量。

您的回调函数应如下所示:

page.open(url, function(status) {

于 2013-03-27T13:56:22.013 回答