我对nodejs很新,并且我很难尝试提出完全清除以下内容的解决方案:
这是我的代码的链接: https://gist.github.com/bingeboy/6087474
答案 0 :(得分:0)
我错过了jsdom.jsdom方法。
var jsdom = require("jsdom");
需要:
var jsdom = require("jsdom").jsdom;
这允许窗口回调加载文件。以前我在错误cb中获取该文件。 var fs = require('fs') ,jsdom = require('jsdom')。jsdom;
var htmlSource = fs.readFileSync(__dirname + "/date.html", "utf8")
, document = jsdom(htmlSource)
, window = document.parentWindow;
console.log(typeof window.document.getElementsByClassName); //function
console.log(window.document.getElementsByTagName('a')[1].innerHTML); //logs link text "311.json"