Skip to content
Messy HTML and window.__STATE__ script transformed by xsel2 into clean typed NDJSON

xsel2

Structured data out of messy HTML and inline script blobs—at C++20 speed, without spinning up a headless browser.
v0.6.0 C++20 Native Zero JS Runtime CLI · Python · C++20 · WASM
$ cmake --preset release && cmake --build build-release -j && ./build-release/xsel2 -d examples/product.dsl --html examples/sample.html
30-Second Hook

From messy real-world HTML to typed JSON in 12 lines

No headless browser, no fragile regex soup, no manual dict assembly. Extract DOM text, normalize prices & URLs, zip <dt>/<dd> pairs, and parse embedded <script> state in one compiled pass.

1. Messy Input (card.html)
<article class="product-card">
  <h1 class="title">  Mechanical   Keyboard   Pro  </h1>
  <span class="price">$1,299.50</span>
  <img class="hero" src="/img/placeholder.png"
       data-src="/img/mk-pro.webp" />
  <a class="manual" href="/docs/mk-pro.pdf">User Manual</a>
  <dl class="specs">
    <dt>Switch</dt><dd>Tactile Brown</dd>
    <dt>Layout</dt><dd>75% Compact</dd>
  </dl>
  <script>
    window.__STATE__ = {
      sku: "MK-75", // unquoted keys & comments
      rating: 4.8,
      inStock: true,
    };
  </script>
</article>
2. xsel2 DSL (product.dsl)
let base = "https://shop.example"
product = Scraper()
  .$("article.product-card") {
    find("h1.title") | clean -> "title"
    | find(".price") | to_number(key="price")
    | find("img.hero", Attribute, ["data-src", "src"])
      | url_join(base) -> "image"
    | find("a.manual", Attribute, "href")
      | url_join(base) -> "manual_url"
    | find_all("dl.specs dt") | clean -> "_k"
    | find_all("dl.specs dd") | clean -> "_v"
    | zip_keys("_k", "_v", "specs")
    | omit_keys(["_k", "_v"])
  }
  .$("script") {
    text | js_block("window.__STATE__ =")
    | parse_js("state")
  }
3. Typed JSON Output
{
  "title": "Mechanical Keyboard Pro",
  "price": 1299.5,
  "image": "https://shop.example/img/mk-pro.webp",
  "manual_url": "https://shop.example/docs/mk-pro.pdf",
  "specs": {
    "Switch": "Tactile Brown",
    "Layout": "75% Compact"
  },
  "state": {
    "sku": "MK-75",
    "rating": 4.8,
    "inStock": true
  }
}
Zero JS Runtime

Deterministic Script Extraction

Heuristically extracts and parses embedded JS/JSON objects—comments, unquoted keys, trailing commas, and string concatenations—without spinning up V8 or a browser.

C++20 Native Core

Built for Throughput

Backed by libxml2, Google RE2, compressed-DFA Aho-Corasick, and jsoncons, with multi-threaded --batch NDJSON streaming.

Write Once

CLI, Python, C++20 & WASM

Author pipelines in the xsel2 DSL (.dsl) or fluent builders and run the exact same engine from the terminal, scraperpy, embedded C++, or the browser.

Batteries Included

End-to-End Shaping

CSS, XPath 1.0, RFC 3986 URLs, absl::Time dates, utf8proc Unicode, fuzzy matching, JMESPath, JSONPath, and JSON Schema validation.

01 Ingest HTML, XML, JSON, CSV, or stdin stream 02 Select CSS, XPath 1.0, or js_block 03 Transform RE2, Aho-Corasick, URL, Date, Fuzzy 04 Shape & Emit JMESPath, JSON Schema, Typed JSON / NDJSON

Try xsel2 Live in WebAssembly

Click any preset pill below or edit the CLI command, HTML input, and xsel2 (.dsl) pipeline—it runs the real C++20 xsel2 engine (libxml2 + RE2 + jsoncons) directly in your browser.

WASM: Ready
$
HTML Input
xsel2 DSL (.dsl)
JSON Output

Same Pipeline Across CLI, Python & C++20

CLI Invocation
# Quick CSS selector extraction
xsel2 -s "h1.product-title" --html examples/sample.html

# Run a .dsl scraper
xsel2 -d examples/product.dsl -n summary --html examples/sample.html

# Multi-threaded batch scraping (NDJSON)
xsel2 -d examples/product.dsl -n summary --batch examples/*.html -j 0
Typed JSON Output
{
"title": "Mechanical Keyboard Pro",
"sku": "MK-PRO-75",
"rating": 4.8
}

Why xsel2 Instead of BeautifulSoup or Playwright?

27.0 s
5,000 Real HTML Files (~3.8 GB, -j 0)
19.9× faster than Python + BeautifulSoup + lxml (535.8 s)
25.6 MB
Single-Thread Peak RSS (-j 1)
4.7× lower than Python + BeautifulSoup + lxml (121.3 MB); 103.0 MB at -j 0
0 ms V8
Embedded <script> Extraction
js_block + parse_js parses JS state without a browser

Measured locally on 5,000 real-world production HTML files (3.51 GiB / 3.77 GB total, ~754 KB avg/file, 12-core Linux x86_64) running identical DOM, regex, and embedded <script> extraction: ./build/xsel2 -d scripts/benchmark.dsl -n real_scrape --batch ... -j 0 (26.97 s, 103.0 MB RSS; single-threaded -j 1: 157.95 s, 25.6 MB RSS) vs. Python 3 + beautifulsoup4 4.14.3 + lxml 6.0.2 (535.76 s, 121.3 MB RSS, requiring custom regex/brace-matching for embedded JS state).

Capability xsel2 BeautifulSoup + regex pup / htmlq Playwright / Puppeteer
CSS Selectors + XPath 1.0 Both built-in CSS (soupsieve), no XPath CSS only CSS + XPath
Embedded <script> JS/JSON without V8 Yes (js_block + parse_js) Manual regex + brittle hacks No Full browser V8 runtime
Multi-threaded batch NDJSON streaming Yes (--batch -j 0) Manual multiprocessing Single-file CLI Heavy browser contexts
RE2, Aho-Corasick, JMESPath & Schema Built into pipeline Separate libraries No External JS libraries
CLI + Python + C++20 + WASM All 4 from one core Python only CLI only Node / Python / etc.

Built For Real-World Extraction

SPA Hydration

Scrape window.STATE at Scale

Extract embedded JS state objects—with comments, unquoted keys, and string concatenation—without booting Chromium or Node.

CI/CD Validation

HTML & JSON Schema Gates

Validate extracted payloads with built-in JSON Schema and JMESPath assertions in a single fast CLI pass.

Text & Logs

Aho-Corasick Multi-Pattern Filter

Match thousands of keywords in linear time with compressed-DFA extract_many and boolean filter rules.

Core Capabilities

HTML/XML Scraping & DSL

CSS selectors & XPath 1.0 / 3.1 extraction (lxml2-query, libxml2), HTML table & metadata extraction, and a compiled .dsl pipeline language.

JS / JSON Block Digger

Heuristically extracts and parses embedded JavaScript/JSON objects, comments, string concatenations, and typed scalars without a JS runtime.

Multi-Pattern & Fuzzy Search

Compressed-DFA Aho-Corasick matcher (AhoCorasick, filter, replace, extract_many) and UTF-8 Jaro-Winkler / Levenshtein fuzzy matching.

JSON, CSV & Schema Queries

Built-in JMESPath, JSONPath, JSON Schema validation, and CSV parsing/serialization powered by jsoncons.

Explore the Docs