9 releases
0.1.8 | Nov 20, 2022 |
---|---|
0.1.7 | Nov 20, 2022 |
#2985 in Parser implementations
Used in npms
18KB
298 lines
HTML parser written in pure Rust,no-std
[dependencies]
loa = "0.1.8"
get innner text from node element
fn main(){
use loa::Getattribute;
let html = include_str!("../index.html");
let body = get_first_element_by_tag_name(html, "head").unwrap();
let text = body.inner_text().unwrap();
println!("{}",text);
}
get node attributes
fn main() {
use loa::{get_elements_by_tag_name, get_first_element_by_tag_name, Getattribute};
let html = include_str!("../index.html");
let p_list: Vec<String> = loa::get_elements_by_tag_name(html, "p");
let a_first: String = loa::get_first_element_by_tag_name(html, "a").unwrap();
let href = a_first.get_attribute("href");
println!("{:?}", p_list);
println!("{:?}", a_first);
println!("{:?}", href);
let buttons = get_elements_by_tag_name(html, "button");
for bu in &buttons{
if bu.contains("Cargo.toml"){
println!("{:?}",bu.get_attribute("title"));
}
}
}
parse html get Vec of nodes
fn main() {
use loa::{get_elements_by_tag_name, get_first_element_by_tag_name, Getattribute};
let html = include_str!("../index.html");
let p_list: Vec<String> = loa::get_elements_by_tag_name(html, "p");
let a_first: String = loa::get_first_element_by_tag_name(html, "a").unwrap();
let href = a_first.get_attribute("href");
let class = a_first.get_attribute("class");
println!("{:?}", p_list);
println!("{:?}", a_first);
println!("{:?}", href);
println!("{:?}", class);
}
parse html and get first element by tag name
fn main() {
use loa::{get_elements_by_tag_name, get_first_element_by_tag_name, Getattribute};
let html = include_str!("../index.html");
let p_list: Vec<String> = loa::get_elements_by_tag_name(html, "p");
let a_first: String = loa::get_first_element_by_tag_name(html, "a").unwrap();
let href = a_first.get_attribute("href");
let class = a_first.get_attribute("class");
println!("{:?}", p_list);
println!("{:?}", a_first);
println!("{:?}", href);
println!("{:?}", class);
}
get all nods by class name
fn main() {
use loa::{
get_elements_by_class_name, get_elements_by_tag_name, get_first_element_by_tag_name,
Getattribute,
};
let html = include_str!("../index.html");
let all_class = get_elements_by_class_name(html, "cake");
println!("{:#?}",all_class);
}
get all a tags href
fn main(){
use loa::*;
let html = include_str!("../index.html");
let hrefs = get_all_a_hrefs(html);
println!("{:#?}",hrefs.unwrap());
}
get first element by class name
fn main() {
use loa::{
get_elements_by_class_name, get_elements_by_tag_name,
get_first_element_by_tag_name,
get_first_element_by_class_name,
Getattribute,
};
let html = include_str!("../index.html");
let class = get_first_element_by_class_name(html, "cake");
println!("{:#?}",class);
}
Dependencies
~3–4.5MB
~75K SLoC