13 个版本
| 0.1.93 | 2021 年 3 月 6 日 | 
|---|---|
| 0.1.92 | 2021 年 3 月 6 日 | 
| 0.1.91 | 2021 年 1 月 21 日 | 
#1995 在 解析器实现
每月 34 次下载
49KB
 1K  SLoC
Capricorn
根据配置解析 HTML。
Capricorn 是一个支持递归和自定义执行顺序的 HTML 解析库。
默认执行顺序
vec![String::from("selects"),
    String::from("each"),
    String::from("select_params"),
    String::from("nodes"),
    String::from("has"),
    String::from("contains")];
    
selects > each > (one or all or fields) > ... text_attr_html > (text or attr or html);
selects > select_params > selects > ... text_attr_html > (text or attr or html);
selects > nodes > has > contains > text_attr_html > (text or attr or html);
支持
| Capricorn | 支持 | 示例 | val 类型 | 
|---|---|---|---|
| 选择元素 | ✔ | 字段名 选择 - element_name | 字符串 | 
| 选择类 | ✔ | 字段名 选择 - .class_name | 字符串 | 
| 选择类元素 | ✔ | 字段名 选择 - .class_name - element_name | 字符串 | 
| 第一个 | ✔ | 字段名 选择 - element_name 节点 first: true | 字符串 | 
| 最后一个 | ✔ | 字段名 选择 - element_name 节点 last: true | 字符串 | 
| eq | ✔ | 字段名 选择 - element_name 节点 eq: 0 | 字符串 | 
| 父节点 | ✔ | 字段名 选择 - element_name 节点 parent: true | 字符串 | 
| 子节点 | ✔ | 字段名 选择 - element_name 节点 children: true | 字符串 | 
| 前兄弟节点 | ✔ | 字段名 选择 - element_name 节点 prev_sibling: true | 字符串 | 
| 后兄弟节点 | ✔ | 字段名 选择 - element_name 节点 next_sibling: true | 字符串 | 
| has_class | ✔ | 字段名 选择 - element_name has class: class_name | 字符串 | 
| has_attr | ✔ | 字段名 选择 - element_name has attr: attr_name | 字符串 | 
| 每一个 | ✔ | 字段名 选择 - element_name each one 选择 - .class_name ... | 字符串 | 
| 每一个全部 | ✔ | 字段名 选择 - element_name each all 选择 - .class_name ... | 数组 | 
| 每一个字段 | ✔ | 字段名 选择 - element_name each fields field_name 选择 - .class_name ... field_name1 选择 - .class_name ... | 映射 | 
| 选择参数 | ✔ | 字段名 选择 - element_name select_params 选择 - .class_name ... | ... | 
| 文本 | ✔ | 字段名 选择 - element_name text_attr_html text: true | 字符串 | 
| 属性 | ✔ | 字段名 选择 - element_name text_attr_html attr: true | 字符串 | 
| HTML | ✔ | 字段名 选择 - element_name text_attr_html html: true | 字符串 | 
| 文本包含 | ✔ | 字段名 选择 - element_name contains contains text - test | 字符串 | 
| 文本不包含 | ✔ | 字段名 选择 - element_name contains not_contains text - test | 字符串 | 
| HTML 包含 | ✔ | 字段名 选择 - element_name contains contains html - test | 字符串 | 
| HTML 不包含 | ✔ | 字段名 选择 - element_name contains not_contains html - test | 字符串 | 
| 执行顺序 | ✔ | 字段名 exec_order - selects - has - nodes 选择 - element_name has class: class_name 节点 first: true | 字符串 | 
| 数据格式分割 | ✔ | 字段名 选择 - element_name data_format 分割 - { key: str } | 数组 | 
| 数据格式分割 | ✔ | 字段名 选择 - element_name data_format 分割 - { key: str, index: 0 } | 字符串 | 
| 数据格式替换 | ✔ | 字段名 选择 - element_name data_format 替换 - str | 字符串 | 
| 数据格式删除 | ✔ | 字段名 选择 - element_name data_format 删除 - str | 字符串 | 
| 数据格式查找 | ✔ | 字段名 选择 - element_name data_format 查找 - regex | 字符串 | 
| 数据格式查找迭代 | ✔ | 字段名 选择 - element_name data_format 查找迭代 - regex | 数组 | 
| 多版本正则匹配错误 | ✔ | regexes_match_parse_html - regex: regex 版本: 1 错误: err_msg | 错误 | 
| 多版本正则匹配字段 | ✔ | regexes_match_parse_html - regex: regex 版本: 1 fields field_name 选择 ... field_name 选择 ... | 映射 | 
解析HTML代码,更多...
let yml = read_file("./test_html/test.yml").unwrap();
let params: parse::HashMapSelectParams = serde_yaml::from_str(&yml).unwrap();
let html = read_file("./test_html/test.html").unwrap();
let r = parse::parse_html(¶ms, &html);
多版本正则匹配解析HTML代码,更多...
let yml = read_file("./test_html/regexes_match_parse_html.yml").unwrap();
let v:  match_html::MatchHtmlVec = serde_yaml::from_str(&yml).unwrap();
let html = read_file("./test_html/test.html").unwrap();
let r =  v.regexes_match_parse_html(html)?;
依赖项
~9–18MB
~235K SLoC