Skip to content
@parsec-html

Parsec

The parsing foundation for the web, in Rust: HTML, CSS, JavaScript, XML, URLs and encodings, each its own crate.

Parsec, the parsing foundation for the web.

Website · Docs · Repository · Benchmarks · Roadmap · Discussions

Parsec is the parsing foundation for the web, in memory-safe Rust: HTML, CSS, JavaScript and XML, one crate at a time, so you build on exactly the parsers you need. It started as an HTML parser, because Netweir needed one faster than Lexbor, and the HTML parser is still the part that's been in use longest. CSS with the cascade, XPath, and the WHATWG Encoding and URL standards sit beside it. JavaScript and XML came in 0.3.0, each with its own tree over shared plumbing.

Netweir, the crawling and extraction framework that first parser was written for, now runs on Parsec the way you would: parsec-web-core and parsec-xpath from crates.io, since Netweir 0.12.0. It pays Parsec back in testing. Every Monday, Netweir's CI parses 300 production pages from a pinned list of 2,709 with Parsec and with html5ever, and fails if Parsec panics, hangs or builds a different tree. Spec suites can't tell you a parser is right on the pages people actually crawl. That run can.

If you parse HTML for a living, you've probably met Lexbor too, directly or through selectolax, PHP's Dom\HTMLDocument, nokolexbor or lazy_html. It's fast, and it follows the spec. What people keep asking it for is the rest: where a node came from in the source, XPath, selectors like :lang() that it parses and never matches, documents you can share across threads, and a node you still hold after it's removed that doesn't read freed memory. Parsec's HTML parser is that list.

use parsec::css::SelectorList;

let doc = parsec::parse("<ul><li class=hit>one<li>two</ul>", false);
let hits = SelectorList::parse("li.hit").unwrap().select(&doc, doc.root());
assert_eq!(doc.text(hits[0]), "one");

And it's quicker at the job. On 13 real pages, 24 MB of Wikipedia, MDN, GitHub, the BBC, the HTML spec and others, Parsec parses 362 MB a second to Lexbor's 242, ahead on every page. Throw a crawl's worst at it, 1,000 pages of broken fragments, re-encoded pages and 10 to 30 MB giants, and it gets through them in 0.99 seconds to Lexbor's 1.93, at under half its peak memory, and nothing crashed. Those are one machine's numbers, an Apple M2 Max on 29 November 2026; the benchmarks have every figure and how to run them yourself.

Start here

  • parsec: the parser, CSS selectors Level 4, XPath 1.0, declarative shadow DOM, the WHATWG Encoding and URL standards, and CSS stylesheets with the cascade. It passes all 7,042 html5lib tokenizer tests it runs and all 3,898 tree-construction tests, and the standards page has the rest.
  • From Python, JavaScript or C: bindings for each live in the same repository, free-threaded Python and WebAssembly included.
  • Install it: 0.3.1 is out. cargo add parsec-web, pip install parsec-web or npm install parsec-web, and the C library is on the release. Getting started takes it from there. Up to 0.2 the packages were parsec-html.
  • Road to the parsing platform: JavaScript, XML and the rest, milestone by milestone. Pick any open item.
  • What's done and what's next: the line between the two is kept sharp.

Get involved

Questions and ideas go to Discussions. Issues labelled good first issue and help wanted are a good place to start, and CONTRIBUTING.md covers the rest. Found a security problem? SECURITY.md says how to report it privately.

Pinned Loading

  1. parsec parsec Public

    The parsing foundation for the web, in Rust: HTML, CSS, JavaScript, XML, URLs and encodings, each its own crate, checked against each standard's own suite. From Rust, Python, JavaScript and C.

    HTML 4 1

Repositories

Showing 3 of 3 repositories

People

This organization has no public members. You must be a member to see who’s a part of this organization.

Top languages

Loading…

Most used topics

Loading…