你能在node.js中操作XML/HTML文档吗?

3

是否可以使用node.js加载XML / HTML文档并执行getElementsByTagName等操作?

3个回答

4

3
Cheerio:是一个专门为服务器设计的核心jQuery的微型、快速和优雅的实现。 点击这里获取更多信息。
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> 

如果您想查询HTML,那么这是最好的答案。 - chovy

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接