feat: Rename Parse to ParseDocument, add ParseNode
This commit is contained in:
parent
947b928a5d
commit
8b4b2ec3cd
1 changed files with 9 additions and 1 deletions
10
html.go
10
html.go
|
@ -12,7 +12,7 @@ type Node struct {
|
|||
*html.Node
|
||||
}
|
||||
|
||||
func Parse(r io.Reader) (*Node, error) {
|
||||
func ParseDocument(r io.Reader) (*Node, error) {
|
||||
n, err := html.Parse(r)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -20,6 +20,14 @@ func Parse(r io.Reader) (*Node, error) {
|
|||
return &Node{n}, nil
|
||||
}
|
||||
|
||||
func ParseNode(r io.Reader) (*Node, error) {
|
||||
n, err := html.ParseFragment(r, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Node{n[0]}, nil
|
||||
}
|
||||
|
||||
func (n *Node) QuerySelector(selector string) *Node {
|
||||
if strings.HasPrefix(selector, "#") {
|
||||
return n.GetElementById(selector[1:])
|
||||
|
|
Loading…
Reference in a new issue