I'm trying to use htmlparser2 (https://www.npmjs.com/package/htmlparser2) to parse a html raw string into json.
But its usage only logs out the tag/text, what I want is the json like its livedemo (http://demos.forbeslindesay.co.uk/htmlparser2/), so that I can filter the elements I want.
Any help or suggestions would be appreciated!
took a look of the source codes, it seems there is a helper method parseDOM that can do the trick:
var htmlparser = require("htmlparser2");
elements = htmlparser.parseDOM(htmlString);
so the elements will be the array of objects like the livedemo.
hope this will help anyone encounters the same problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With