安装:
npm install cheerio例子:
let cheerio = require('cheerio')
let $ = cheerio.load('<h2 class="title">Hello world</h2>')
$('h2.title').text('Hello there!')
$('h2').addClass('welcome')
$.html()
本文介绍如何利用Node.js的Cheerio库来轻松地操作HTML文档,包括安装步骤及示例代码,展示了如何加载HTML字符串、选择元素、修改文本内容及添加CSS类。
安装:
npm install cheeriolet cheerio = require('cheerio')
let $ = cheerio.load('<h2 class="title">Hello world</h2>')
$('h2.title').text('Hello there!')
$('h2').addClass('welcome')
$.html()
1289

被折叠的 条评论
为什么被折叠?