All Projects → remarkablemark → html-dom-parser

remarkablemark / html-dom-parser

Licence: MIT License
📝 HTML to DOM parser.

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
typescript
32286 projects
shell
77523 projects

Projects that are alternatives of or similar to html-dom-parser

Htmlparser2
The fast & forgiving HTML and XML parser
Stars: ✭ 3,299 (+5791.07%)
Mutual labels:  dom, htmlparser2
Preact Markup
⚡️ Render HTML5 as VDOM, with Components as Custom Elements!
Stars: ✭ 167 (+198.21%)
Mutual labels:  parse, dom
Cheerio
Fast, flexible, and lean implementation of core jQuery designed specifically for the server.
Stars: ✭ 24,616 (+43857.14%)
Mutual labels:  dom, htmlparser2
Skrape.it
A Kotlin-based testing/scraping/parsing library providing the ability to analyze and extract data from HTML (server & client-side rendered). It places particular emphasis on ease of use and a high level of readability by providing an intuitive DSL. It aims to be a testing lib, but can also be used to scrape websites in a convenient fashion.
Stars: ✭ 231 (+312.5%)
Mutual labels:  parse, dom
Html React Parser
📝 HTML to React parser.
Stars: ✭ 846 (+1410.71%)
Mutual labels:  parse, dom
Swiftsoup
SwiftSoup: Pure Swift HTML Parser, with best of DOM, CSS, and jquery (Supports Linux, iOS, Mac, tvOS, watchOS)
Stars: ✭ 3,079 (+5398.21%)
Mutual labels:  parse, dom
debug.js
Debugger of JavaScript, by JavaScript, for JavaScript
Stars: ✭ 19 (-66.07%)
Mutual labels:  dom
hotshot
Takes screenshots of DOM elements
Stars: ✭ 19 (-66.07%)
Mutual labels:  dom
parse-cloud-class
Extendable way to set up Parse Cloud classes behaviour
Stars: ✭ 40 (-28.57%)
Mutual labels:  parse
eval-estree-expression
Safely evaluate JavaScript (estree) expressions, sync and async.
Stars: ✭ 22 (-60.71%)
Mutual labels:  parse
decoy
jQuery plugin to make decoys for your elements.
Stars: ✭ 53 (-5.36%)
Mutual labels:  dom
shaven
DOM building utility & Template engine based on JsonML + syntax sugar
Stars: ✭ 66 (+17.86%)
Mutual labels:  dom
node-htmlmetaparser
A `htmlparser2` handler for parsing rich metadata from HTML. Includes HTML metadata, JSON-LD, RDFa, microdata, OEmbed, Twitter cards and AppLinks.
Stars: ✭ 44 (-21.43%)
Mutual labels:  htmlparser2
warframe-worldstate-parser
📗 An Open parser for Warframe's Worldstate in Javascript
Stars: ✭ 50 (-10.71%)
Mutual labels:  parse
crawler CIA CREST
R-crawler for CIA website (CREST)
Stars: ✭ 15 (-73.21%)
Mutual labels:  parse
UndoRedo.js
A powerful and simple JavaScript library provides a history for undo/redo functionality. Just like a time machine! 🕐
Stars: ✭ 19 (-66.07%)
Mutual labels:  dom
fox
A Fortran XML library
Stars: ✭ 51 (-8.93%)
Mutual labels:  dom
wutpl
高性能模板引擎 (js template)
Stars: ✭ 85 (+51.79%)
Mutual labels:  dom
expresol
Library for executing customizable script-languages in python
Stars: ✭ 11 (-80.36%)
Mutual labels:  parse
micell
A collection of functions for front-end development
Stars: ✭ 16 (-71.43%)
Mutual labels:  dom

html-dom-parser

NPM

NPM version Build Status codecov NPM downloads

HTML to DOM parser that works on both the server (Node.js) and the client (browser):

HTMLDOMParser(string[, options])

The parser converts an HTML string to a JavaScript object that describes the DOM tree.

Example

const parse = require('html-dom-parser');
parse('<p>Hello, World!</p>');

Output:

[
  Element {
    type: 'tag',
    parent: null,
    prev: null,
    next: null,
    startIndex: null,
    endIndex: null,
    children: [
      Text {
        type: 'text',
        parent: [Circular],
        prev: null,
        next: null,
        startIndex: null,
        endIndex: null,
        data: 'Hello, World!'
      }
    ],
    name: 'p',
    attribs: {}
  }
]

Replit | JSFiddle | Examples

Install

NPM:

npm install html-dom-parser --save

Yarn:

yarn add html-dom-parser

CDN:

<script src="https://unpkg.com/html-dom-parser@latest/dist/html-dom-parser.min.js"></script>
<script>
  window.HTMLDOMParser(/* string */);
</script>

Usage

Import or require the module:

// ES Modules
import parse from 'html-dom-parser';

// CommonJS
const parse = require('html-dom-parser');

Parse empty string:

parse('');

Output:

[];

Parse string:

parse('Hello, World!');
[
  Text {
    type: 'text',
    parent: null,
    prev: null,
    next: null,
    startIndex: null,
    endIndex: null,
    data: 'Hello, World!'
  }
]

Parse element with attributes:

parse('<p class="foo" style="color: #bada55">Hello, <em>world</em>!</p>');

Output:

[
  Element {
    type: 'tag',
    parent: null,
    prev: null,
    next: null,
    startIndex: null,
    endIndex: null,
    children: [ [Text], [Element], [Text] ],
    name: 'p',
    attribs: { class: 'foo', style: 'color: #bada55' }
  }
]

The server parser is a wrapper of htmlparser2 parseDOM but with the root parent node excluded.

The client parser mimics the server parser by using the DOM API to parse the HTML string.

Testing

Run server and client tests:

npm test

Generate HTML coverage report for server tests:

npx nyc report --reporter=html

Lint files:

npm run lint
npm run lint:fix

Test TypeScript declaration file for style and correctness:

npm run lint:dts

Release

Release and publish are automated by Release Please.

Special Thanks

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].