r/webscraping • u/Equivalent-Golf1638 • 11h ago
Years of personal scraping tools into a compiled pipeline DSL (xsel2)
For years, I maintained and refined a huge personal tool (xsel1) for my own scraping work. After using it on all kinds of messy real-world pages, I started noticing a clear pattern in everything I was doing: select, process, save to a dictionary, and repeat—with some sub-selections and value edits happening in between. At some point, I stopped seeing it as just scraping scripts and started seeing it as an assembly line. Basically a small processor where the values you're currently transforming live on the stack, and the output dictionary you're building up is the heap. With the help of AI, I recently rewrote that entire private tool from scratch into a clean, open-source C++20 library called xsel2, built directly around that mental model. I really hope this resonates with how others view and solve the same problem—and isn't just my own way of looking at it.
How it looks in practice
Instead of writing glue code to parse HTML, run regexes, clean URLs, and dig through embedded <script> variables, you write a pipeline (either in a .dsl file or using the C++20 / Python APIs).
For example, pulling product data and an unquoted window.__STATE__ JS object in one 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")
| omit_keys(["_k", "_v"])
}
.$("script") {
text | js_block("window.__STATE__ =") | parse_js("state")
}A few things I built into it:
- No headless browser / V8: js_block + parse_js extracts and parses messy JS objects (comments, unquoted keys, trailing commas) heuristically without booting a JS runtime.
- Fast C++20 core: Built on top of libxml2, Google RE2, Aho-Corasick, and jsoncons. On a local test of 5,000 real HTML files (~3.8 GB), it ran through the whole batch in ~27s (compared to ~535s with BeautifulSoup + lxml).
- Use it anywhere: Same engine works as a multi-threaded CLI (streaming NDJSON), a Python package (pip install xsel2 - “import scraperpy”), a C++20 library, or in the browser.
Where things are right now
Honestly, I wrote a lot of xsel1 as a bit of a mess, backed by TDD, real-world data tests, and standing on the shoulders of giants—copying and porting great ideas and pieces from existing open-source projects. Right now, my biggest challenge is figuring out how to distill what's actually useful for everyone else out of the thousands of steps I accumulated in xsel1.
If you want to mess around with the DSL without installing anything, I compiled the C++20 engine to WebAssembly so you can run it directly on the docs page: Docs & Live WASM Playground: https://mateusgpe.github.io/xsel2/playground/
Happy to answer any questions about how the pipeline engine works, hear what you think of the syntax, or get feedback on which steps actually matter in your own scraping workflows! If you want to make any final tweaks—like adding a GitHub repo link next to the docs link—just share the URL and I can drop it right in.



