# htmlparser2
[![NPM version](http://img.shields.io/npm/v/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
[![Downloads](https://img.shields.io/npm/dm/htmlparser2.svg?style=flat)](https://npmjs.org/package/htmlparser2)
[![Build Status](http://img.shields.io/travis/fb55/htmlparser2/master.svg?style=flat)](http://travis-ci.org/fb55/htmlparser2)
[![Coverage](http://img.shields.io/coveralls/fb55/htmlparser2.svg?style=flat)](https://coveralls.io/r/fb55/htmlparser2)
A forgiving HTML/XML/RSS parser.
The parser can handle streams and provides a callback interface.
## Installation
npm install htmlparser2
A live demo of htmlparser2 is available [here](https://astexplorer.net/#/2AmVrGuGVJ).
## Usage
```javascript
const htmlparser2 = require("htmlparser2");
const parser = new htmlparser2.Parser(
{
onopentag(name, attribs) {
if (name === "script" && attribs.type === "text/javascript") {
console.log("JS! Hooray!");
}
},
ontext(text) {
console.log("-->", text);
},
onclosetag(tagname) {
if (tagname === "script") {
console.log("That's it?!");
}
}
},
{ decodeEntities: true }
);
parser.write(
"Xyz