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();
Comments
Post a Comment