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

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

参考资料

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

安装

powershell 复制代码
npm i cheerio [email protected]

引入

js 复制代码
import * as cheerio from 'cheerio';

使用

js 复制代码
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.
相关推荐
艾恩小灰灰5 小时前
深入理解CSS中的`transform-origin`属性
前端·javascript·css·html·web开发·origin·transform
自带五拨片7 小时前
XHTMLConverter把docx转换html报java.lang.NullPointerException异常
java·html
工呈士9 小时前
HTML与Web性能优化
前端·html
码起来呗10 小时前
基于微信小程序的走失儿童帮助系统-项目分享
微信小程序·小程序
雯0609~11 小时前
vue3:十一、主页面布局(修改左侧导航条的样式)
前端·javascript·html
大樊子12 小时前
微信小程序路由跳转实现详解
微信小程序·小程序
Rey_family12 小时前
HTML 表单学习笔记
笔记·学习·html
Monly2113 小时前
Uniapp:swiper(滑块视图容器)
uni-app
张张张31214 小时前
4.21—4.22学习总结 JavaWeb:HTML-CSS
前端·css·学习·html
七七小报15 小时前
uniapp-商城-32-shop 我的订单-订单详情和组件goods-list
uni-app