search_node.go

This commit is contained in:
2026-03-02 22:26:28 +03:00
parent 33b08bdd00
commit 7db719e3ff
9 changed files with 134 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
//go:build ignore
package scraper
import (
@@ -17,7 +18,7 @@ var body = &html.Node{
var ErrNotAnElementNode = errors.New("not a html.ElementNode")
func parseFragment(s string) (*html.Node, error) {
func ParseFragment(s string) (*html.Node, error) {
n, err := html.ParseFragment(strings.NewReader(s), body)
if err != nil {
return nil, err
@@ -33,13 +34,13 @@ func MatchElemAttr(s string, n *html.Node) (bool, error) {
if n1.Type != html.ElementNode {
return false, errors.Join(
ErrNotAnElementNode,
ErrNotAnElementNode,
errors.New("s isn's a html.ElementNode"),
)
)
}
if n.Type != html.ElementNode {
return false, errors.Join(
ErrNotAnElementNode,
ErrNotAnElementNode,
errors.New("n isn's a html.ElementNode"),
)
}
@@ -51,7 +52,6 @@ func MatchElemAttr(s string, n *html.Node) (bool, error) {
return false, nil
}
func SearchElemAttr2(s string, n2 *html.Node) (chan *html.Node, error) {
ch := make(chan *html.Node)
var crawl func(*html.Node)