当前位置: 首页 > article >正文

【uniapp小程序】使用cheerio去除字符串中的HTML标签并获取纯文本内容

【uniapp小程序】使用cheerio去除字符串中的HTML标签并获取纯文本内容

  • 参考资料
  • 安装
  • 引入
  • 使用

参考资料

【博主:AIpoem】uniapp小程序 使用cheerio处理网络请求拿到的dom数据
cheerio文档:https://github.com/cheeriojs/cheerio/wiki/Chinese-README

安装

npm i cheerio --@0.22.0

引入

import * as cheerio from 'cheerio';

使用

const $ = cheerio.load('<div><h1 class="content">hello world!</h1><p class="text">This is a <strong>test</strong> paragraph one.</p><p>This is a <strong>test</strong> paragraph two.</p></div>');
const content = $('body').text();
console.log(content); // hello world!This is a test paragraph one.This is a test paragraph two.
const content2 = $('h1').text();
console.log(content2); // hello world!
const content3 = $('p').text();
console.log(content3); // This is a test paragraph one.This is a test paragraph two.
const content4 = $('p.text').text();
console.log(content4); // This is a test paragraph one.

http://www.kler.cn/news/342251.html

相关文章:

  • 性能优化-SQL查询优化技巧全解
  • 服装生产管理的数字化转型:SpringBoot框架
  • Serilog文档翻译系列(八) - 记录器的生命周期、可靠性
  • Android -- [SelfView] 自定义多色渐变背景板
  • C/C++语言三大结构练习题(持续更新。。。)
  • 什么是矩阵系统,怎么选择矩阵系统,怎么oem贴牌,怎么源码搭建
  • Oracle RAC IPC Send timeout detected问题分析处理
  • 免费气象可视化的前端框架概述
  • 每日一面 day03
  • 论文翻译 | Fairness-guided Few-shot Prompting for LargeLanguage Models
  • 每天一个数据分析题(四百九十八)- Apriori算法
  • 毕业设计选题:基于php+vue+uniapp的新闻资讯小程序
  • CocosCreator基于jenkins自动构建
  • MQTT vs HTTP:谁更适合物联网?
  • [软件工程]—TFTP协议简要解析
  • wasm在云原生领域的运用
  • 【进阶OpenCV】 (6)--指纹识别
  • 每天一个数据分析题(四百九十九)- 数据集
  • 跨界的胜利:机器学习与神经网络的物理之光
  • Spring Boot中使用RabbitMQ 生产消息和消费消息