cheeio是jquery核心功能的一个快速灵活而又简洁的实现,主要是为了用在服务器端需要对DOM进行操作的地方官方文档
- cheeio主要用于在服务端处理dom,例如一个get请求请求回来一个html页面,这个时候想要从这个页面中提取出来信息就可以用cheeio
const 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>
- 常用api
- load 解析html
使用cheeio手动加载html文档<ul id="fruits"> <li class="apple">Apple</li> <li class="orange">Orange</li> <li class="pear">Pear</li> </ul>
方法一var cheerio = require('cheerio'), $