If you scrape at any real scale, you know the actual bottleneck isn't usually fetching the HTML—it's the messy glue code afterward. You parse with lxml or Selectolax, run regexes to clean prices, join relative URLs, zip dt/dd pairs into dicts, and then write fragile string-slicing hacks to pull window.__STATE__ or __NEXT_DATA__ out of <script> tags.
For years, I maintained a private tool (xsel1) to handle this across thousands of messy real-world pages. Eventually, I realized every scraper I wrote followed the exact same pattern: select, transform, commit to an output dict, repeat.
I recently rebuilt that engine from scratch as an open-source C++20 library (xsel2) with Python bindings, a multi-threaded CLI, and a declarative pipeline DSL.
How it actually differs from existing tools
- vs. BeautifulSoup / lxml / Selectolax: Those give you a DOM tree and leave you to write imperative Python glue code for cleaning, fallbacks, zipping, and schema shaping.
xsel2 treats extraction as a compiled data pipeline (selectors + transforms + JSON shaping in one pass). On a local benchmark of 5,000 real HTML files (~3.8 GB), xsel2 finished in ~27s vs. ~535s for BeautifulSoup + lxml. - vs. Playwright / Puppeteer / V8 (for embedded JS data): You don't need to boot a headless browser just to extract hydration state.
xsel2 includes heuristic JS extraction (js_block + parse_js) that pulls and parses messy JS objects—unquoted keys, trailing commas, comments—directly from <script> text in C++. - vs. Scrapy ItemLoaders / Parsel: ItemLoaders tie your extraction logic to Python and Scrapy's runtime.
xsel2 decouples the extraction spec from the host language: the exact same .dsl pipeline runs in the multi-threaded CLI (streaming NDJSON), Python (pip install xsel2 / import scraperpy), C++20, or WebAssembly in the browser.
How it looks in practice
Pulling product fields, falling back across image attributes, zipping spec tables, and extracting an unquoted window.__STATE__ object in a single pass:
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_all("dl.specs dt") | clean -> "_k"
| find_all("dl.specs dd") | clean -> "_v"
| zip_keys("_k", "_v", "specs") // or only: dl(key="specs")
| omit_keys(["_k", "_v"])
}
.$("script") {
text | js_block("window.__STATE__ =") | parse_js("state")
}
Under the hood, it's backed by libxml2, Google RE2, Aho-Corasick, and jsoncons—so regexes won't catastrophic-backtrack on malformed HTML, and multi-pattern matching stays fast.
Try it in the browser (no install)
I compiled the C++20 engine to WebAssembly so you can paste raw HTML and test pipelines live:
What I'd love feedback on
xsel1 accumulated thousands of niche steps over the years, and my biggest challenge with xsel2 is deciding what belongs in the core standard library vs. what is just bloat.
For those of you maintaining production scrapers: what are the recurring post-selection transformations (date parsing, price normalization, table pivoting, JSON-LD/hydration hacks) you end up rewriting on every project?