px普贤教程PuXian
普贤教程 › 包参考

htmlparse 包

HTML 解析(子集)

项值
包名htmlparse
版本0.2.0
可用版本0.1.0 / 0.2.0
入口htmlparse.px
分类数据格式与编解码
文件数 / 行数1 / 315

安装与引入

bash
pxpkg init          # 首次
pxpkg add htmlparse@0.2.0
pxpkg install
px
import htmlparse
所属分类教程:数据格式与编解码

公开接口

函数参数
hp_parses
hp_findel, tag
hp_textel
hp_attrel, name
其余 16 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
hp_trims
hp_find_froms, sub, start
hp_is_spacec
hp_tagraw
hp_voidtag
hp_find_recel, tag, out
hp_decode_entitiess
hp_find_by_attrel, tag, attr_name, attr_value
hp_find_by_attr_recel, tag, attr_name, attr_value, out
hp_find_firstel, tag
hp_inner_htmlel
hp_outer_htmlel
hp_table_parseel
hp_extract_linksel
hp_extract_imagesel
hp_strip_tagss

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/htmlparse —— HTML 解析(子集)
------------------------------------------------------------
纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。
hp_parse(s)     → Ok(root dict) | Err
元素 = {tag, attrs: dict, children: [元素|文本], parent};
root.tag = "#root"。注释跳过;void 标签(br/img/input/…)不嵌套;
属性支持 name="v" / name='v' / name(布尔,值为 "")。
hp_find(el, tag) → [元素](DFS,大小写不敏感)
hp_text(el)      → str(递归拼接文本)
hp_attr(el, name) → string | null(缺省 null)
说明:非严格容错(未闭合标签按栈顶弹出处理;不校验证实/实体解码)。
============================================================