Fast HTML parser with CSS selector API for Node.js and browsers, powered by Rust (scraper crate).
npm install fastscraper-js
# or
pnpm add fastscraper-jsimport { parseDocument, parseFragment } from "fastscraper-js"
// Parse a full HTML document
const doc = parseDocument(`
<html>
<body>
<h1 class="title">Hello</h1>
<ul>
<li><a href="https://example.com">Link 1</a></li>
<li><a href="https://example.org">Link 2</a></li>
</ul>
</body>
</html>
`)
// Select all matching elements
const links = doc.select("a")
for (const link of links) {
console.log(link.attr("href")) // "https://example.com", "https://example.org"
console.log(link.text()) // "Link 1", "Link 2"
}
// Select the first matching element
const h1 = doc.selectFirst("h1")
console.log(h1?.text()) // "Hello"
console.log(h1?.tagName()) // "h1"
console.log(h1?.hasClass("title")) // true
// Parse an HTML fragment
const frag = parseFragment('<p class="note">Hello <strong>world</strong></p>')
const p = frag.selectFirst("p")
console.log(p?.innerHtml()) // "Hello <strong>world</strong>"
console.log(p?.outerHtml()) // '<p class="note">Hello <strong>world</strong></p>'Bundlers (Vite, webpack, etc.) automatically select the WASM build via the browser condition in package.json. No configuration needed.
import { parseDocument } from "fastscraper-js"
// → resolves to the WASM build automatically in browser environmentsThe WASM runtime is provided by the optional dependency fastscraper-js-wasm32-wasi, which is installed automatically alongside the main package.
By default, the native binary is used. To force the WASM build in Node.js:
NAPI_RS_FORCE_WASI=true node your-script.jsRequires Rust and Node.js 18+.
pnpm install
pnpm build
pnpm test