Compare commits

...

3 Commits

Author SHA1 Message Date
33b08bdd00 Merge branch 'master' of https://git.nkpl.cc/twocookedfaggots/scraper 2026-02-12 01:12:34 +03:00
45e84573e9 errros 2026-02-12 01:11:25 +03:00
f41daf8f88 errors 2026-02-12 01:10:58 +03:00

View File

@@ -15,7 +15,7 @@ var body = &html.Node{
DataAtom: atom.Body,
}
var ErrNotAnElementNode = errors.New("not an ElementNode")
var ErrNotAnElementNode = errors.New("not a html.ElementNode")
func parseFragment(s string) (*html.Node, error) {
n, err := html.ParseFragment(strings.NewReader(s), body)
@@ -25,19 +25,27 @@ func parseFragment(s string) (*html.Node, error) {
return n[0], nil
}
func MatchElemAttr(s string, n2 *html.Node) (bool, error) {
func MatchElemAttr(s string, n *html.Node) (bool, error) {
n1, err := parseFragment(s)
if err != nil {
return false, err
}
if !(n1.Type == html.ElementNode &&
n2.Type == html.ElementNode) {
return false, ErrNotAnElementNode
if n1.Type != html.ElementNode {
return false, errors.Join(
ErrNotAnElementNode,
errors.New("s isn's a html.ElementNode"),
)
}
if n.Type != html.ElementNode {
return false, errors.Join(
ErrNotAnElementNode,
errors.New("n isn's a html.ElementNode"),
)
}
if n1.Data == n2.Data &&
slices.Equal(n1.Attr, n2.Attr) {
if n1.Data == n.Data &&
slices.Equal(n1.Attr, n.Attr) {
return true, nil
}
return false, nil