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.
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.
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>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")
}{
"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
}
}Heuristically extracts and parses embedded JS/JSON objects—comments, unquoted keys, trailing commas, and string concatenations—without spinning up V8 or a browser.
Backed by libxml2, Google RE2, compressed-DFA Aho-Corasick,
and jsoncons, with multi-threaded --batch NDJSON streaming.
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.
CSS, XPath 1.0, RFC 3986 URLs, absl::Time dates, utf8proc Unicode,
fuzzy matching, JMESPath, JSONPath, and JSON Schema validation.
js_block 03 Transform RE2, Aho-Corasick, URL, Date, Fuzzy 04 Shape & Emit JMESPath, JSON Schema, Typed JSON / NDJSON xsel2 Live in WebAssemblyClick 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.
xsel2 DSL (.dsl) # 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{
"title": "Mechanical Keyboard Pro",
"sku": "MK-PRO-75",
"rating": 4.8
}import scraperpy
s = scraperpy.ScraperPy()
(
s.select("h1.product-title").text().squish().set("title")
.select(".price").text().regex_extract(r"([0-9]+\.[0-9]+)", 1).set("price")
.select("script").text().js_block("window.__PRODUCT_STATE__ =").parse_js("state", True)
)
result = s.from_file("examples/sample.html"){
"title": "Mechanical Keyboard Pro",
"price": "149.99",
"state": {
"sku": "MK-PRO-75",
"rating": 4.8,
"inStock": True,
"tags": ["mechanical", "wireless", "rgb"]
}
}#include "scraper/scraper.hpp"
#include <iostream>
int main() {
scraper::ScraperBuilder builder;
builder.Select("h1.product-title").Text().Squish().Set("title");
auto result = builder.scrape_from_file("examples/sample.html");
std::cout << jsoncons::pretty_print(result) << '\n';
}{
"title": "Mechanical Keyboard Pro"
}xsel2 Instead of BeautifulSoup or Playwright?-j 0)-j 1)-j 0<script> Extractionjs_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. |
window.STATE at ScaleExtract embedded JS state objects—with comments, unquoted keys, and string concatenation—without booting Chromium or Node.
Validate extracted payloads with built-in JSON Schema and JMESPath assertions in a single fast CLI pass.
Match thousands of keywords in linear time with compressed-DFA extract_many and boolean filter rules.
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.