Languages
[Edit]
EN

Node.js - parse html to DOM with htmlparser2 library

7 points
Created by:
Root-ssh
178180

In this short article, we would like to show how in Node.js parse HTML to Simple DOM - it is not real DOM but is enough in many cases giving good parser performance (check performance section).

Note: the main advantage of this library is portability (Works in any JavaScript - even with React and SSR)

Library installation

Edit

Usage example

Edit

index.js file: 

Screenshot:

Node.js HTML parsing with htmlparser2 library.
Node.js HTML parsing with htmlparser2 library.

TypeScript version

Edit

index.ts file:

See also

Edit
  1. JavaScript - parse HTML

  2. JavaScript - parse XML

References

Edit
  1.  https://www.npmjs.com/package/htmlparser2
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join