htmlparser2HTML/XML 解析器
htmlparser2 是一个 fast & forgiving HTML/XML 解析器。
npm install htmlparser2
htmlparser2 的 live demo:https://astexplorer.net/#/2AmVrGuGVJ
htmlparser2 本身提供了一个回调接口,允许以最小的分配来消耗文档。为了获得更符合人体工程学的体验,可阅读下面的 Getting a DOM。
const htmlparser2 = require("htmlparser2"); const parser = new htmlparser2.Parser({ onopentag(name, attributes) { /* * This fires when a new tag is opened. * * If you don't need an aggregated `attributes` object, * have a look at the `onopentagname` and `onattribute` events. */ if (name === "script" && attributes.type === "text/javascript") { console.log("JS! Hooray!"); } }, ontext(text) { /* * Fires whenever a section of text was processed. * * Note that this can fire at any point within text and you might * have to stich together multiple pieces. */ console.log("-->", text); }, onclosetag(tagname) { /* * Fires when a tag is closed. * * You can rely on this event only firing when you have received an * equivalent opening tag before. Closing tags without corresponding * opening tags will be ignored. */ if (tagname === "script") { console.log("That's it?!"); } }, }); parser.write( "Xyz <script type='text/javascript'>const foo = '<<bar>>';</ script>" ); parser.end();
Output (with multiple text events combined):
--> Xyz
JS! Hooray!
--> const foo = '<<bar>>';
That's it?!
评论
FastXmlJava XML 解析器
FastXml是一个简单、高性能、极少内存消耗的基于xmlpull机制的javaxml解析器。性能最好的xml解析器:性能是VTD-XMl的3倍,是XPP3/MXP1的2倍,详见性能测试数据和测试代码
FastXmlJava XML 解析器
0
SHXMLParseriOS XML 解析器
SHXMLParser是一个基于NSXMLParser构建的易用的XML解析器,可转换XML数据到Objective-C对象。
SHXMLParseriOS XML 解析器
0
AEXMLiOS XML 解析器
AEXML是简单,轻量级的iOSXML解析器,使用Swift编写。AEXML包括三个对象:AEXMLElement(baseclass),AEXMLDocument(inheritedfromprev
AEXMLiOS XML 解析器
0
node-htmlparserHTML / XML / RSS 解析器
NodeHtmlParser 一个可以用 JS 编写的 HTML / XML / RSS 解析器,适
node-htmlparserHTML / XML / RSS 解析器
0
node-htmlparserHTML / XML / RSS 解析器
NodeHtmlParser一个可以用JS编写的HTML/XML/RSS解析器,适用于浏览器和NodeJS(是的,尽管它的名称在任何现代浏览器中都可以正常使用)。解析器可以处理流(分块数据),并支持用
node-htmlparserHTML / XML / RSS 解析器
0