Cheerio 互动版

在线工具推荐: Three.js AI纹理开发包 - YOLO合成数据生成器 - GLTF/GLB在线编辑 - 3D模型格式在线转换 - 可编程3D场景编辑器

过滤

.siblings()

获取某元素的所有同级元素。(当然除了它自己)

$('.pear').siblings().length; //=> 2

.children([selector])

获取某元素的孩子节点。可以传入参数在所有的孩子节点中进行筛选。

$('#fruits').children().length; //=> 3

$('#fruits').children('.pear').text(); //=> Pear

.filter(selector) & .filter(function(index))

在cheerio对象集合中进行条件筛选。

$('li').filter('.orange').attr('class'); //=> orange

$('li').filter(function(i, el) {
  // this === el
  return $(this).attr('class') === 'orange';
}).attr('class') //=> orange