我试图使用jsdom来分析一些html内容。我看到的示例使用了基于html内容的jsdom.jsdom文档的jsdom.jsdom()方法。
但是,当我尝试遵循这些示例时,我的文档没有.createWindow()方法。
var getaPage=function (req, res, callback) {
jsdom.defaultDocumentFeatures={
FetchExternalResources : ['script'],
ProcessExternalResources : ['script'],
MutationEvents : '2.0',
QuerySelector : false
};
var htmlDoc = '<html lang="en-US">' +
'</html>';
var tstDocument=jsdom.jsdom(htmlDoc);
for (var attr in tstDocument){
if (attr == 'createWindow') {
console.log('Found it');
}else{
console.log('not it');
};
};
};当我运行这个程序时,我会得到一堆“不是它”而不是“找到它”。
为什么我没有.createWindow()方法?
发布于 2014-10-21 18:01:08
随着1.0版本的发布,jsdom的API发生了很大的变化。createWindow()方法来自旧的API。您应该能够通过访问tstDocument.defaultView获得文档的窗口,就像在浏览器中一样。
https://stackoverflow.com/questions/26492552
复制相似问题