首页 > 解决方案 > 在 Typescript (Protrator) 中解析 HTML 文档的方法(想要断言 html 文件下的元数据)?

问题描述

我想在量角器 Typescript 中断言下载的 html 文件的元数据

标签: typescriptprotractor

解决方案


感谢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();

推荐阅读