typescript - 在 Typescript (Protrator) 中解析 HTML 文档的方法(想要断言 html 文件下的元数据)?
问题描述
我想在量角器 Typescript 中断言下载的 html 文件的元数据
解决方案
感谢guyz的努力,不需要我自己回答的问题,如果需要请参考我的创建方法-
使用的 npm 库npm install htmlparser2
从这里参考
var fs = require('fs-extra');
var htmlparser = require("htmlparser2");
var parser = new htmlparser.Parser({
onopentag: function (name: string, attribs: string{ type: string; }) {
if (name === tagName && attribs.type === attrType) {
console.log("=====================");
}
},
ontext: function (text: any) {
console.log("-->", text);
},
onclosetag: function (tag: string) {
if (tag === tagName) {
console.log("======================");
}
}
}, { decodeEntities: true });
var rawHtml: string = fs.createReadStream(filePath).pipe(parser);
parser.write(rawHtml);
parser.end();
推荐阅读
- wagtail - 如何添加一个类别片段,用于不同的片段
- airflow - 气流UnicodeDecodeError:'ascii'编解码器无法解码字节0xe2
- python - 使用 zip 在数据框中编织列
- excel - 计算我们增加给定日期范围的次数
- ffmpeg - 使用 libav 将 RGBA 帧编码为 MP4 但输出一团糟
- javascript - 如何在 React 中将重复的 JSX 抽象为高阶组件
- excel - 通过 VBA 将文件嵌入 Excel 会损坏文件
- graph-algorithm - 这个 LCA 算法可以吗,在其他地方使用过吗?
- sql - 尝试查找有行和无行的视图
- docker - 如何使用 jre-alpine 基础镜像创建 Scala Play 应用程序的 Docker 镜像