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