Quickstart
Get xsel2 built, tested, and running in a few minutes—or try it immediately in your browser below.
xsel2 DSL (.dsl) Prerequisites
- C++20 compiler: GCC 11+, Clang 14+, or MSVC
- CMake: 3.24 or newer
- libxml2 development headers (optional): e.g.
libxml2-dev(Debian/Ubuntu) orlibxml2-devel(Fedora/RHEL). If not installed on the system, CMake automatically falls back to fetching and buildingGNOME/libxml2via CPM (controlled by-DXSEL_FETCH_LIBXML2=AUTO|ON|OFF, defaultAUTO). - XPath 3.1 support (optional): Enabled by default (
-DXSEL_USE_XPATH3=ON|OFF, defaultON) forxpath3/XPath3vialxml2-query. - Python 3 development headers: e.g.
python3-dev(Debian/Ubuntu) orpython3-devel(Fedora/RHEL), for_scraperpy/scraperpy - Internet access on first configure:
cmake/CPM.cmakeautomatically fetchesjsoncons,pybind11,lxml2-query,abseil-cpp,re2,utf8proc,Catch2, andlibxml2(when not found on the system).
Build & Test
CMakePresets.json provides three ready-to-use configure presets:
| Preset | Compiler | Build Directory | Purpose |
|---|---|---|---|
debug |
System default | build/ |
Development & unit tests |
release |
System default | build-release/ |
Optimized (-O3) binaries & bindings |
asan-ubsan |
Clang (clang / clang++) |
build-asan/ |
AddressSanitizer + UndefinedBehaviorSanitizer |
Build and run the Catch2 test suite with the debug preset:
cmake --preset debugcmake --build build -jctest --test-dir build --output-on-failureFor an optimized release build:
cmake --preset releasecmake --build build-release -jctest --test-dir build-release --output-on-failureInstalling Binaries (Optional)
Each preset sets CMAKE_INSTALL_PREFIX to install/ in the repository root. To install xsel2 and _scraperpy:
cmake --install build-releaseHelper Scripts (scripts/)
Convenience scripts wrap CMake presets, CTest filtering, and Python wheel packaging:
# Configure and build (presets: debug [default], release, asan-ubsan)./scripts/build.sh -p debug -j 8 [-c|--clean]
# Run tests (optionally build first and/or filter CTest regex)./scripts/test.sh -p debug [-b|--build] [-R <regex>] [-j 8]
# Build and test in one command./scripts/build_and_test.sh [-p debug|release|asan-ubsan] [-c|--clean] [-R <regex>] [-j 8]
# Build and verify Python sdist/wheels in dist/./scripts/pack_python.sh [--wheel-only|--sdist-only] [-p "3.13 3.14"] [-t|--test] [-c|--clean]
# Build the WebAssembly module for the browser playground./scripts/build_wasm.shNote: When
uvis found during CMake configuration,ctestalso registers and runspython_pytest(tests/test_python.py) andcli_pytest(tests/test_cli.py) alongside the Catch2 C++ tests andcli_integration_tests.
5-Minute Walkthrough
The examples/ directory includes a sample HTML page (examples/sample.html), an xsel2 DSL scraper file (examples/product.dsl), and a Python script (examples/scrape_example.py).
1. Run a quick CSS selector from the CLI
./build/xsel2 -s "h1.product-title" --html examples/sample.html2. Run an xsel2 (.dsl) scraper
# Run the "summary" scraper from examples/product.dsl
./build/xsel2 -d examples/product.dsl -n summary --html examples/sample.html
# Or stream HTML through stdin (pipe mode)
cat examples/sample.html | ./build/xsel2 -d examples/product.dsl -n summary -c{
"title": "Mechanical Keyboard Pro",
"sku": "MK-PRO-75",
"rating": 4.8
}3. Run the Python example (scraperpy)
Add both the build directory (which contains _scraperpy*.so) and the repository root (which contains scraperpy/) to PYTHONPATH:
PYTHONPATH=build:. python3 examples/scrape_example.pyPYTHONPATH=build:. python3 examples/table_financial.pyPYTHONPATH=build:. python3 examples/article_news.pyPYTHONPATH=build:. python3 examples/ecommerce_catalog.pyPYTHONPATH=build:. python3 examples/social_hydration.pyPYTHONPATH=build:. python3 examples/all_steps_showcase.pyNext Steps
- WASM Playground — Try
xsel2CLI &.dslpipelines directly in the browser - CLI Reference —
xsel2options, pipe mode, and multi-threaded batch processing - Python Bindings (
scraperpy) — Fluent pipelines,InsertMode,AhoCorasick, and JSON queries - DSL Manual — Complete
.dslsyntax and step-by-step reference - C++20 API Guide — Linking
scraper,digger,xsel_query, andxsel_common