chore: update readme

Signed-off-by: Young Xu <xuthus5@gmail.com>
This commit is contained in:
Young Xu 2024-09-22 18:58:31 +08:00
parent 703122b00b
commit 01702ba1c4

35
README.md Normal file
View File

@ -0,0 +1,35 @@
# 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
}
```