Closed vovchynniko closed 3 years ago
What version number of htmlquery
library you uses? I test on my local, it output correct.
func main() {
s := `<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
</head>
<body>
<div>
<div class="body">
<strong>We need this.</strong>
<strong>Not this.</strong>
</div>
<strong>And we definitely don't need this.</strong>
</div>
</body>
</html>`
doc, _ := htmlquery.Parse(strings.NewReader(s))
nodes := htmlquery.Find(doc, `//div[@class="body"]//text()[contains(.,"need")]`)
for _, node := range nodes {
fmt.Println(htmlquery.InnerText(node))
fmt.Println(strings.Repeat("-", 40))
}
}
$ go run main.go
We need this.
----------------------------------------
try update you htmlquery
and xpath library.
Hello zhengchun,
Thank you for your great library. I'd like to file one issue with
text()
.Having this simple HTML page
I want to extract "We need this." text node. Here's my code:
Unfortunately, the result is a bit more than I asked for:
Thank you and stay safe :)