Fast HTML Parser

1.0.1 · abandoned · verified Sun Apr 19

Fast HTML Parser (version 1.0.1) is an HTML parsing library designed for high performance and low-cost processing of large HTML files, generating a simplified DOM tree with basic element query support. It prioritizes speed, often outperforming alternatives like older versions of `htmlparser2` in its benchmarks. Key differentiators include its focus on raw parsing speed and a simplified DOM structure. However, this package is effectively abandoned, with its last release over a decade ago. It lacks active maintenance, modern features, and critical security updates. For current projects requiring a fast HTML parser, `node-html-parser` (a separate, actively maintained package that appears to be a spiritual successor or re-implementation) is the recommended alternative, offering similar performance goals with ongoing development and broader feature support.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates parsing HTML, accessing the root element, querying elements by ID and class, and extracting text and raw HTML content.

const HTMLParser = require('fast-html-parser');

const htmlContent = `
  <div id="container">
    <h1>Welcome</h1>
    <p class="intro">Hello, <span class="name">World</span>!</p>
    <ul>
      <li>Item 1</li>
      <li>Item 2</li>
    </ul>
  </div>`;

const root = HTMLParser.parse(htmlContent);

console.log('Root structure:\n', root.firstChild.structure);

const container = root.querySelector('#container');
if (container) {
  const welcomeHeading = container.querySelector('h1');
  console.log('\nWelcome Heading Text:', welcomeHeading ? welcomeHeading.text : 'Not found');

  const introParagraph = container.querySelector('.intro');
  console.log('Intro Paragraph HTML:', introParagraph ? introParagraph.rawText : 'Not found');

  const spanName = introParagraph ? introParagraph.querySelector('.name') : null;
  console.log('Span Name Text:', spanName ? spanName.text : 'Not found');
}

view raw JSON →