概述
cheerio 是 node 的第三方模块,使用语法和 jquery 类似,可以使用 cheerio 来解析 html 文件,进而对文件进行修改等操作。
安装
1 | npm install cheerio |
示例
下面示例会读取 test.html 文件,然后修改其 #wraper 节点的内容。
1 |
|
在文件 modfiyhtml.js 中操作 test.html 文件
1 | const fs = require("fs"); |
输出结果:
1 | <html lang="en"><head> |
cheerio 是 node 的第三方模块,使用语法和 jquery 类似,可以使用 cheerio 来解析 html 文件,进而对文件进行修改等操作。
1 | npm install cheerio |
下面示例会读取 test.html 文件,然后修改其 #wraper 节点的内容。
1 | <!DOCTYPE html> |
在文件 modfiyhtml.js 中操作 test.html 文件
1 | const fs = require("fs"); |
输出结果:
1 | <!DOCTYPE html><html lang="en"><head> |