search_node.go
This commit is contained in:
17
util.go
17
util.go
@@ -4,6 +4,9 @@ import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/html"
|
||||
"golang.org/x/net/html/atom"
|
||||
)
|
||||
|
||||
func containsWord(s, substr string) (match bool) {
|
||||
@@ -22,3 +25,17 @@ func containsWord(s, substr string) (match bool) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var body = &html.Node{
|
||||
Type: html.ElementNode,
|
||||
Data: "body",
|
||||
DataAtom: atom.Body,
|
||||
}
|
||||
|
||||
func ParseFragment(s string) (*html.Node, error) {
|
||||
n, err := html.ParseFragment(strings.NewReader(s), body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return n[0], nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user