node.js检查dom像标准的JavaScript

如何从html源document创builddocument对象,并使用document.*函数,如node.js中的getElementById

如果你只是想使用类似jQuery的API遍历HTML标记,更好的select是cheerio 。

jsdom是一个完整的DOM实现,甚至可以运行一个页面附带的JS。 结果,这很重。 如果你不需要任何的function,cheerio快8倍。

 var cheerio = require('cheerio'), $ = cheerio.load('<h2 class="title">Hello world</h2>'); $('h2.title').text('Hello there!'); $('h2').addClass('welcome'); $.html(); //=> <h2 class="title welcome">Hello there!</h2> 

你可能想要像DOM的jsdom实现的东西 。