【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.
相关推荐
anyup4 小时前
uni-app X 全屏引导页组件,一套支持 App、H5、小程序多端引导
前端·架构·uni-app
a1117765 小时前
动森UI组件(开源 html animal-island-ui )
前端·javascript·ui·开源·html
我是伪码农5 小时前
小程序100-125
开发语言·小程序·php
ZC跨境爬虫6 小时前
跟着 MDN 学CSS day_15:(掌握CSS背景与边框的创造性用法)
前端·css·ui·html·tensorflow
蜡笔小电芯7 小时前
【Electron】第3章—HTML 页面与基础 UI 开发
ui·electron·html
a1117769 小时前
闪卡网页 第五人格 html 开源
前端·html
java小吕布10 小时前
HyperFrames:写 HTML 就能渲染视频,专为 AI 智能体打造的开源渲染框架
人工智能·html·音视频
a11177610 小时前
【无标题】
前端·开源·html
scan7241 天前
langgraphy条件边
前端·javascript·html