From ec4f16e2745a3a0715e98166f3e2ed18c9194ccf Mon Sep 17 00:00:00 2001 From: BroodjeAap Date: Sun, 15 Jan 2023 11:10:18 +0000 Subject: [PATCH] fixed xpath/css innerHTML --- scraping.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/scraping.go b/scraping.go index b77d6dd..7d7f992 100644 --- a/scraping.go +++ b/scraping.go @@ -354,16 +354,14 @@ func getFilterResultXPath(filter *Filter) { switch selectType { case "inner": { - // if the child is a text node, theres nothing else (?), so just append that - if node.FirstChild != nil && node.FirstChild.Type == html.TextNode { - filter.Results = append(filter.Results, html.UnescapeString(node.FirstChild.Data)) + if node.FirstChild == nil { continue } - // else, theres more nodes, turn them all into a string and add that as a result + var result bytes.Buffer for child := node.FirstChild; child != nil; child = child.NextSibling { var b bytes.Buffer - html.Render(&b, node) + html.Render(&b, child) result.WriteString(b.String()) } filter.Results = append(filter.Results, html.UnescapeString(result.String())) @@ -421,16 +419,14 @@ func getFilterResultCSS(filter *Filter) { switch selectType { case "inner": { - // if the child is a text node, theres nothing else (?), so just append that - if node.FirstChild != nil && node.FirstChild.Type == html.TextNode { - filter.Results = append(filter.Results, html.UnescapeString(node.FirstChild.Data)) + if node.FirstChild == nil { continue } - // else, theres more nodes, turn them all into a string and add that as a result + var result bytes.Buffer for child := node.FirstChild; child != nil; child = child.NextSibling { var b bytes.Buffer - html.Render(&b, node) + html.Render(&b, child) result.WriteString(b.String()) } filter.Results = append(filter.Results, html.UnescapeString(result.String()))