node.js - How i can use htmlparser2 to parse html files? -


i using node.js , need parse html file. have used htmlparser2 , parses string in parser.write("string") method. can parse html file using html parser? if yes how?

help appreciated?

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?!");     } } }, {decodeentities: true}); parser.write("xyz <script type='text/javascript'>var foo = '<<bar>>';</script>"); parser.end(); 

https://github.com/fb55/htmlparser2

http://demos.forbeslindesay.co.uk/htmlparser2/


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -