#htmlparser2 [](https://npmjs.org/package/htmlparser2) [](http://travis-ci.org/fb55/htmlparser2) [](https://david-dm.org/fb55/htmlparser2)
A forgiving HTML/XML/RSS parser written in JS for NodeJS. The parser can handle streams (chunked data) and supports custom handlers for writing custom DOMs/output.
##Installing
npm install htmlparser2
A live demo of htmlparser2 is available at http://demos.forbeslindesay.co.uk/htmlparser2/
##Usage
```javascript
var htmlparser = require("htmlparser2");
var parser = new htmlparser.Parser({
onopentag: function(name, attribs){
if(name === "script" && attribs.type === "text/javascript"){
console.log("JS! Hooray!");
}
},
ontext: function(text){
console.log("-->", text);
},
onclosetag: function(tagname){
if(tagname === "script"){
console.log("That's it?!");
}
}
});
parser.write("Xyz