html

package module
v0.0.0-...-648a86e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrValueCannotAddress = errors.New("value can not address")
	ErrValueNotBasicKind  = errors.New("value not a basic kind")
	ErrValueCast          = errors.New("value string cast error")
)

Functions

func BindMapField

func BindMapField(doc *goquery.Selection, field MapField, params map[string]string) ([]any, error)

func BindStruct

func BindStruct(sel *goquery.Selection, out any, options StructOptions) error

func ReplaceTemplate

func ReplaceTemplate(template string, params map[string]string) (s string)

ReplaceTemplate 模板替换

Types

type MapField

type MapField struct {
	Name   string     `json:"name,omitempty" xml:"name,omitempty"`     // 字段名称
	Value  string     `json:"value,omitempty" xml:"value,omitempty"`   // 模板值
	Select string     `json:"select,omitempty" xml:"select,omitempty"` // 选择器
	Attr   string     `json:"attr,omitempty" xml:"attr,omitempty"`     // 属性选择
	Format string     `json:"format,omitempty" xml:"format,omitempty"` // 格式化
	Find   string     `json:"find,omitempty" xml:"find,omitempty"`     // 结果再查找(正则表达式)
	Repl   string     `json:"repl,omitempty" xml:"repl,omitempty"`     // 结果查找后再替换(正则替换表达式)
	List   bool       `json:"list,omitempty" xml:"list,omitempty"`     // 是否列表
	Split  string     `json:"split,omitempty" xml:"split,omitempty"`   // 是否对字段再进行拆分
	Type   string     `json:"type,omitempty" xml:"type,omitempty"`     // 类型: time, duration, string, int, float, bool, 默认 string
	Fields []MapField `json:"fields,omitempty" xml:"fields,omitempty"` // 字段
}

type Process

type Process = func(resp *http.Response) error

func Html

func Html(process func(s *goquery.Selection) error) Process

func Map

func Map(out *[]any, field MapField, params map[string]string) Process

Map 将HTML解析为Map, out 必须为 *any

func Struct

func Struct(out any, selection string, options StructOptions) Process

Struct 将HTML解析为Struct

type StructOptions

type StructOptions struct {
	SelectTag string // select
	AttrTag   string // attr
	FormatTag string // format
	FindTag   string // find
	ReplTag   string // repl
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL