I am trying to parse for a specific tag inside 2 websites. I need to do that in an async way but to display the results to the user at the end. I tried using htmlParser2 but I am not using it correctly. For example how can I parse all the h2 tags from the html... Here is a code I was trying before:
var htmlparser = require('htmlparser2');
var parser = new htmlparser.Parser({
onopentag: function(name, attribs){
if(name === "h2"){
//
}
},
ontext: function(text){
//
},
onclosetag: function(tagname){
if(tagname === "h2"){
//
}
}
});
parser.write(html_txt);
parser.end();
I am quite new to node.js so any help will be more than great. Thanks