lol-html
rental
Our great sponsors
lol-html | rental | |
---|---|---|
8 | 3 | |
1,390 | 211 | |
1.9% | - | |
5.7 | 1.2 | |
about 1 month ago | almost 3 years ago | |
Rust | Rust | |
BSD 3-clause "New" or "Revised" License | GNU General Public License v3.0 or later |
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
lol-html
-
Ask HN: A fast, Rust HTML parser that works?
So I'm doing some web scraping in Rust, and so I will need to parse HTML. [scraper](https://docs.rs/scraper/latest/scraper/) (which uses [html5ever](https://github.com/servo/html5ever)) is doing fine except that it's the bottleneck of my application.
So I need a faster parser. I've tried [tl](https://docs.rs/tl/latest/tl/) which would've been perfect except that it doesn't actually work on the HTML I have. When I try to `query_selector` the elements I need, it returns nothing.
[Kuchiki](https://docs.rs/kuchiki/latest/kuchiki/) is abandonded.
I couldn't figure out how to get [lol-html](https://github.com/cloudflare/lol-html) to work for me (it's designed for re-writing HTML, whatever that means). It doesn't seem to have an API to extract the inner text of an element.
[html5gum](https://github.com/untitaker/html5gum) seems to be just an HTML tokenizer, or otherwise just too low-level. I have not yet tried [quick-xml](https://github.com/tafia/quick-xml/) but judging from the README, it's pretty low-level too. I mean, if these are the only options left then I will try them. Otherwise, I would love to use a parser that's faster but as ergonomic as `scraper` or `tl`.
At this point, I would be happy with an Lxml bridge/port of some sort. I don't need to mutate HTML, just parse and read data from it.
-
How much Rust work is actually going on at Cloudflare?
I'm also in the Workers org but I have had a bit of interaction with Rust. There's some Rust in the Workers runtime using lol-html for HTMLRewriter as well as some tooling and there's the full blown workers-rs framework that I work on, but that's about it for the Rust I work on regularly.
- Is there a library for manipulating HTML?
- pup: Parsing HTML at the Command Line
-
Texting Robots: Taming robots.txt with Rust and 34 million tests
Thanks again and happy to answer any questions! My current unreleased Rust projects include a web crawler that uses Tokio + Tokio Console + Reqwest with this crate for robots.txt and a fast text extraction library using lol-html that I am planning to sprinkle with some minimal ML to get Readability.js style intelligent extraction (with training in Python). See Fathom for an example of the ML approach I'll likely take.
-
Like JQ, but for HTML
I’d like to see a tool using lol-html [0] and their CSS selector API as a streaming HTML editor.
[0] https://github.com/cloudflare/lol-html
- Things you can’t do in Rust (and what to do instead)
-
Problems with building a backend app in Rust in 2020
Cloudflare has open sourced lol-html, a "Low output latency streaming HTML parser/rewriter with CSS selector-based API". Is that what you are looking for?
rental
-
Workaround for self-referential structs?
Before choosing rental, one should be aware that, according to a huge disclaimer on crates.io, rental is no longer maintained or supported. (The repository is archived.)
-
Things you can’t do in Rust (and what to do instead)
Overall this is a great blog post that highlights many of the things newcomers to Rust try out or are surprised why they are so hard and discouraged. One nit:
> Luckily there are some crates that take the solution and present a safe interface, such as the rental and once_self_cell crates.
Please don't link to the rental crate any more, as it's out of maintenance. The github repo is archived [0] and the maintainer explicitly stated they don't want to hand over maintenance to someone else. Thankfully the maintainer was still available to implement one tiny patch recently to make it not fire a future compat lint [1], but given this announcement by the maintainer, generally I'd recommend people to move to maintained alternatives. Especially new projects should build on something else. Instead of rental, the blog post could mention ouroboros. Also as a nit, the once_self_cell crate has been renamed to self_cell. There is also selfstack but I haven't used it so don't know how good it is.
[0]: https://github.com/jpernst/rental/commit/213671ab3aab3452efd...
[1]: https://github.com/rust-lang/rust/issues/84428
I agree with the general sentiment, and much of the stuff I build has little activity after an initial phase of getting it "done". However, I'm still around to merge important patches. But in the case of rental, the git repository is archived and most importantly the author has written that "users are encouraged to explore other solutions". Recently users of rental have been facing a future compat lint in rental, and thankfully the maintainer fixed it, but I think their intent of urging users to alternatives remains as immediately afterwards the repo got re-archived.
What are some alternatives?
actor-rust-scraper - Experimental scraper in Rust suited for running locally or on the Apify platform. Inspired by Apify SDK.
cargo-expand - Subcommand to show result of macro expansion
tq - Perform a lookup by CSS selector on an HTML input
wg - Coordination repository of the embedded devices Working Group
yq - Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
index-list - A doubly-linked list implementation in safe Rust using vector indexes
tools - all-in collection of productivity scripts, CLI tools, utility libraries, fuse filesystems, and also some stuff
not-yet-awesome-embedded-rust - A collection of items that are not yet awesome in Embedded Rust
hq - lightweight command line HTML processor using CSS and XPath selectors
xidel - Command line tool to download and extract data from HTML/XML pages or JSON-APIs, using CSS, XPath 3.0, XQuery 3.0, JSONiq or pattern matching. It can also create new or transformed XML/HTML/JSON documents.
blog.rust-lang.org - Home of the Rust and Inside Rust blogs