soupy is a library for parsing and querying like BeautifulSoup.
MIT + Apache 2.0
https://crates.io/crates/soupy
https://github.com/hankjordan/soupy
9 messages · Page 1 of 1 (latest)
soupy is a library for parsing and querying like BeautifulSoup.
MIT + Apache 2.0
https://crates.io/crates/soupy
https://github.com/hankjordan/soupy
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<title>Hello!</title>
</head>
<body>
<h1>Hello World!</h1>
<p>This is a simple paragraph.</p>
<div class="parent">
<div class="child">
<div id="item">
<p>Nested item</p>
<a href="https://example.com">Example Link</a>
</div>
</div>
</div>
</body>
<img class="self-closing"/>
<!-- Simple comment -->
</html>
use soupy::prelude::*;
const HTML: &str = include_str!("example.html");
fn main() {
let soup = Soup::new(HTML).expect("Failed to parse HTML");
println!("Soup {:?}", soup);
for node in soup.tag("a").attr_name("href") {
println!("Href {:?}", node.get("href"));
}
for node in soup.tag("p") {
println!("Paragraph {:?}", node);
}
if let Some(item) = soup.attr("id", "item").first() {
println!("Found item {:?}", item);
}
}
Output
soup Soup { ... }
href Some("https://example.com")
paragraph Element { name: "p", attrs: {}, children: [Text("This is a simple paragraph.")] }
paragraph Element { name: "p", attrs: {}, children: [Text("Nested item")] }
Found item Element { name: "div", attrs: {"id": "item"}, children: [Element { name: "p", attrs: {}, children: [Text("Nested item")] }, Element { name: "a", attrs: {"href": "https://example.com"}, children: [Text("Example Link")] }] }
Could we use unit structs as identifiers instead of &str?
what do you mean by 'identifier' ?
Hello. Are you looking for contributors on this ?
Any help is appreciated, though barring things like examples and tests (and mutable access) it's more or less complete
suggestions welcome though, I can't think of anything else I'd really like to add
v0.8.0 has been releasedParser traitQueryItem::query() method