loa

Crates.ioloa
lib.rsloa
version0.1.8
sourcesrc
created_at2022-11-04 01:53:41.516535
updated_at2022-11-20 09:51:30.756883
descriptionHTML parser written in pure Rust,no-std
homepage
repositoryhttps://framagit.org/zinso/loa
max_upload_size
id704753
size23,831
zinso (zinso)

documentation

https://docs.rs/loa

README

HTML parser written in pure Rust,no-std

Crates.io Rust license

[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);
}
Commit count: 0

cargo fmt