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

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

参考资料

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

安装

powershell 复制代码
npm i cheerio --@0.22.0

引入

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.
相关推荐
窝子面1 天前
uni-app的初体验
uni-app
笨笨狗吞噬者1 天前
【uniapp】微信小程序实现自定义 tabBar
前端·微信小程序·uni-app
2501_933907211 天前
如何选择性价比高的宁波小程序开发服务公司?
科技·微信小程序·小程序
雪芽蓝域zzs2 天前
uniapp MD5加密 加密传输 密码加密
uni-app
nhc0882 天前
贵阳纳海川科技・棋牌室行业数字化解决方案
科技·微信小程序·小程序·软件开发·小程序开发
xingyynt2 天前
【HTML+CSS】使用HTML与后端技术连接数据库
css·数据库·html
2501_915909062 天前
iOS 抓包不越狱,代理抓包 和 数据线直连抓包两种实现方式
android·ios·小程序·https·uni-app·iphone·webview
给钱,谢谢!2 天前
记录uni-app Vue3 慎用 Teleport,会导致页面栈混乱
前端·vue.js·uni-app
CHU7290352 天前
让知识传递更顺畅:在线教学课堂APP的功能设计
前端·人工智能·小程序
AI前端老薛2 天前
小程序中简单 Loading 效果关键帧动画
小程序