Documentation ¶
Overview ¶
Package scan implements structures that can scan HTML into go values.
Index ¶
- func Attr(n *html.Node, key string) (val string, ok bool)
- func Text(n *html.Node) string
- type Options
- type ScanFunc
- func Bytes(opts Options) ScanFunc
- func Float(opts Options) ScanFunc
- func Int(opts Options) ScanFunc
- func ScannerOf(t reflect.Type, opts Options) (ScanFunc, error)
- func Slice(opts Options, t reflect.Type) (ScanFunc, error)
- func String(opts Options) ScanFunc
- func Struct(opts Options, t reflect.Type) (ScanFunc, error)
- func Uint(opts Options) ScanFunc
- type Scanner
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ScanFunc ¶
ScanFunc represents a scanner func.
The function receives a destination to scan into and the source as the root html node.
Scan functions can be nested, for example a slice scan func will typically nest its element types, a struct scan func will nest its field types.
func ScannerOf ¶
ScannerOf returns a scanner of type t using opts.
If the type is not supported, the method returns an error with type information.
Some types which define tags will return an error if the tag cannot be compiled.
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner implements a type scanner.
The scanner extracts raw HTML data into registered types. When the scanner sees a new type it will analyze it and create a scanfunc that can be re-used with different html nodes.
The scanner supports the follow types:
- int
- uint
- float
- string
- byte
- struct
The scanner also supports exporting multiple html nodes into a slice of the above types.
The scanner uses tags to lookup data in the root html node and extract its data, for example:
AuthorURLs []string `css:"a.author@href"`
Will export all hrefs from anchor tags that have the class `.author`.