XU XUv0.16.0

#html/query

导入方式: #html/query

公开 API: 1 函数, 6 方法, 2 类型, 0 常量, 0 方法集

标准库包 `#html/query`。

struct Attr

XuAPI
pub struct Attr {
    pub key string
    pub value string
}

用途

承载 key、value 等属性的结构体。

公开字段

key string
键
value string
字段(string)

struct Doc

XuAPI
pub struct Doc {
    pub tags []string
    pub texts []string
    pub firsts []int
    pub nexts []int
    pub parents []int
    pub attr_keys []string
    pub attr_vals []string
    pub attr_next []int
    pub attr_head []int
}

用途

承载 tags、texts、firsts、nexts、parents 等属性的结构体。

公开字段

tags []string
字段([]string)
texts []string
字段([]string)
firsts []int
字段([]int)
nexts []int
字段([]int)
parents []int
字段([]int)
attr_keys []string
字段([]string)
attr_vals []string
字段([]string)
attr_next []int
字段([]int)
attr_head []int
字段([]int)

parse

XuAPI
pub fn parse(html0 string) Doc

用途

解析输入。

参数

html0 string
html0(string)

返回值

Doc — 该类型的值

(&Doc) root

XuAPI
pub fn (d &Doc) root() int

用途

在 &Doc 上执行 root 操作。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。

返回值

int — 该类型的值

(&Doc) tag

XuAPI
pub fn (d &Doc) tag(n int) string

用途

&Doc 上的操作:标签。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(&Doc) attr

XuAPI
pub fn (d &Doc) attr(n int, key string) string

用途

在 &Doc 上执行 attr 操作。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。
n int
数量、长度或上限(int)
key string
键(string)

返回值

string — 结果字符串

(&Doc) text_content

XuAPI
pub fn (d &Doc) text_content(n int) string

用途

&Doc 上的操作:执行 text content 操作。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。
n int
数量、长度或上限(int)

返回值

string — 结果字符串

(&Doc) query_all

XuAPI
pub fn (d &Doc) query_all(selector string) []int

用途

&Doc 上的操作:执行 query all 操作。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。
selector string
selector(string)

返回值

[]int — 切片结果

(&Doc) query

XuAPI
pub fn (d &Doc) query(selector string) int

用途

&Doc 上的操作:查询串。

参数

d &Doc
本次调用使用的 Doc 实例;以只读借用传入,调用方仍持有实例。
selector string
selector(string)

返回值

int — 该类型的值