Closed scharph closed 2 years ago
htmlquery.InnerText
will output target element node all inner text including its child nodes.
Try change XPath to html/body/pre/code/span[2]/following-sibling::text()
Another way is using //pre/code/text()
get all text node and then concat it.
list := htmlquery.Find(doc, "//pre/code/text()")
for _, node := range list {
fmt.Println(strings.TrimSpace(htmlquery.InnerText(node)))
}
Thank you .. works as expected 👍
I want to access the inner text " bar" from the node '\<code>' which also has some '\<span>' elements inside
Actual result: "foo: bar;" Expected: "bar"
For some reason the span's inner texts are also included.. how can I prevent this?
Tried it with this path tester extendsclass.com/xpath-tester with the query "//body/pre/code/text()" and it returns the expected value
Any ideas?