Hello, can you recommend good crates to parse html and query it with css selectors?
Why don't you perform a quick search on crates.io?
I recommend scraper.
I used to try scraper
and select
in a repo, but I finally chose select
without remembering why.
Hey!
For parsing HTML and querying with CSS selectors in Rust, I’d recommend the scraper
crate. It’s very user-friendly and allows you to use CSS selectors to extract data from HTML.
Here’s a quick example:
rust
use scraper::{Html, Selector};
let html = "<html>...</html>";
let document = Html::parse_document(html);
let selector = Selector::parse("div.class_name").unwrap();
for element in document.select(&selector) {
println!("{}", element.inner_html());
}
You can also check out select
, another crate, but scraper
is probably the best choice for your needs.
If you’re doing web scraping and running into anti-scraping measures, you might want to consider using Multilogin to avoid detection. It helps manage multiple browser profiles and avoid blocks. Check it out here.
Good luck!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.