jsdom 4.0 发布,JavaScript 的 HTML 解析器

jopen 9年前

jsdom 4.0 发布,该版本基于全新的 vm 模块,避免上下文原生模块依赖。使用上更加简单,无需 C++ 工具链进行编译。改进介绍请看这里

jsdom 是 WHATWG DOM 和 HTML 标准的 JavaScript 实现,主要用于 io.js 框架。

示例代码:

// Count all of the links from the io.js build page  var jsdom = require("jsdom");    jsdom.env(    "https://iojs.org/dist/",    ["http://code.jquery.com/jquery.js"],    function (errors, window) {      console.log("there have been", window.$("a").length - 4, "io.js releases!");    }  );

或者:

// Run some jQuery on a html fragment  var jsdom = require("jsdom");    jsdom.env(    '<p><a class="the-link" href="/misc/goto?guid=4958522268617377854">jsdom!</a></p>',    ["http://code.jquery.com/jquery.js"],    function (errors, window) {      console.log("contents of a.the-link:", window.$("a.the-link").text());    }  );
来自:http://www.oschina.net/news/59915/jsdom-4-0-released