goh/README.md
Young Xu 01702ba1c4 chore: update readme
Signed-off-by: Young Xu <xuthus5@gmail.com>
2024-09-22 18:58:31 +08:00

35 lines
652 B
Markdown

# goh
> use golang to parse html and get node values
## Usage
```go
package main
import (
"fmt"
"strings"
"gitter.top/common/goh"
)
func main() {
reader := strings.NewReader(`<!DOCTYPE html><html lang="en"><head></head><body><h1>hello world</h1><div class="foo"><div id="bar">bar</div></div></body></html>`)
parser, err := goh.NewParser(reader)
if err != nil {
panic(err)
}
h1Value, err := parser.Find("h1").Value()
if err != nil {
panic(err)
}
fmt.Println("h1 value:", h1Value) // hello world
barValue, err := parser.Find("div.foo #bar").Value()
if err != nil {
panic(err)
}
fmt.Println("bar value:", barValue) // bar
}
```