XU XUv0.16.0

#html/query

import: #html/query

counts: 1 functions, 6 methods, 2 types, 0 constants, 0 method sets

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

Structure encapsulating key, value.

Public fields

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

Structure encapsulating tags, texts, firsts, nexts, parents.

Public fields

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

Execute root on &Doc.

Parameters

d &Doc
The Doc instance used by this call (borrow).

Returns

int — a value of this type

(&Doc) tag

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

Purpose

Execute tag on &Doc.

Parameters

d &Doc
The Doc instance used by this call (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

Execute attr on &Doc.

Parameters

d &Doc
The Doc instance used by this call (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

Operation on &Doc: text content.

Parameters

d &Doc
The Doc instance used by this call (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
The Doc instance used by this call (borrow).
selector string
selector (string)

Returns

[]int — slice result

(&Doc) query

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

Purpose

Execute query on &Doc.

Parameters

d &Doc
The Doc instance used by this call (borrow).
selector string
selector (string)

Returns

int — a value of this type