XU XUv0.8.8
中文

API

#html/query

import: #html/query

counts: 1 fns, 6 methods, 2 types, 0 consts, 0 ifaces

Minimal HTML DOM + CSS query subset for scraping. Selectors: tag, #id,.class, tag.class, descendant (a b), child (a > b). Flat node pool (json.Doc style) — no recursive owning trees.

struct Attr

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

Purpose

Minimal HTML DOM + CSS query subset for scraping. Selectors: tag, #id,.class, tag.class, descendant (a b), child (a > b). Flat node pool (json.Doc style) — no recursive owning trees.

Parameters

key string
key
value string
field (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
}

Purpose

Public struct `Doc`.

Parameters

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

parse

XuAPI
pub fn parse(html0 string) Doc

Purpose

Parse the input.

Parameters

html0 string
html0 (string)

Returns

Doc — a value of this type

(&Doc) root

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

Purpose

Call `root` on `&Doc`.

Parameters

d &Doc
receiver &Doc (borrow)

Returns

int — a value of this type

(&Doc) tag

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

Purpose

Call `tag` on `&Doc`.

Parameters

d &Doc
receiver &Doc (borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&Doc) attr

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

Purpose

Call `attr` on `&Doc`.

Parameters

d &Doc
receiver &Doc (borrow)
n int
count, length, or limit (int)
key string
key (string)

Returns

string — result string

(&Doc) text_content

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

Purpose

Method on `&Doc`: text content.

Parameters

d &Doc
receiver &Doc (borrow)
n int
count, length, or limit (int)

Returns

string — result string

(&Doc) query_all

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

Purpose

Iterative query — avoid recursive array ownership pitfalls.

Parameters

d &Doc
receiver &Doc (borrow)
selector string
selector (string)

Returns

[]int — slice result

(&Doc) query

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

Purpose

Call `query` on `&Doc`.

Parameters

d &Doc
receiver &Doc (borrow)
selector string
selector (string)

Returns

int — a value of this type