htmlparser2 HTML/XML 解析器开源项目

我要开发同款
白开水不加糖2021年08月26日
236阅读

技术信息

开源地址
https://gitee.com/mirrors/htmlparser2
授权协议
MIT

作品详情

htmlparser2是一个fast&forgivigHTML/XML解析器。

pmistallhtmlparser2

htmlparser2的 livedemo:https://astexplorer.et/#/2AmVrGuGVJ

htmlparser2本身提供了一个回调接口,允许以最小的分配来消耗文档。为了获得更符合人体工程学的体验,可阅读下面的GettigaDOM。

costhtmlparser2=require("htmlparser2");costparser=ewhtmlparser2.Parser({oopetag(ame,attributes){/**Thisfireswheaewtagisopeed.**Ifyoudo'teedaaggregated`attributes`object,*havealookatthe`oopetagame`ad`oattribute`evets.*/if(ame==="script"&&attributes.type==="text/javascript"){cosole.log("JS!Hooray!");}},otext(text){/**Fireswheeverasectiooftextwasprocessed.**Notethatthiscafireataypoitwithitextadyoumight*havetostichtogethermultiplepieces.*/cosole.log("-->",text);},oclosetag(tagame){/**Fireswheatagisclosed.**Youcarelyothisevetolyfirigwheyouhavereceiveda*equivaletopeigtagbefore.Closigtagswithoutcorrespodig*opeigtagswillbeigored.*/if(tagame==="script"){cosole.log("That'sit?!");}},});parser.write("Xyz<scripttype='text/javascript'>costfoo='<<bar>>';</script>");parser.ed();

Output(withmultipletextevetscombied):

-->XyzJS!Hooray!-->costfoo='<<bar>>';That'sit?!

功能介绍

htmlparser2 是一个 fast & forgiving HTML/XML 解析器。
npm install htmlparser2 htmlparser2 的 live demo:...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论