htmlquery
htmlquery is a Go library that allows you to parse and extract data from HTML documents using XPath expressions. It provides a simple and intuitive API for traversing and querying the HTML tree structure, and it is built on top of the popular Goquery library.
Example Use
```go package main
import ( "fmt" "log"
"github.com/antchfx/htmlquery" )
func main() {
// Parse the HTML string
doc, err := htmlquery.Parse([]byte(<html>
<body>
<h1>Hello, World!</h1>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
</html>))
if err != nil {
log.Fatal(err)
}
// Extract the text of the first
element h1 := htmlquery.FindOne(doc, "//h1") fmt.Println(htmlquery.InnerText(h1)) // "Hello, World!"
// Extract the text of all