Use golang to quickly get html node data
Go to file
Young Xu 01702ba1c4 chore: update readme
Signed-off-by: Young Xu <xuthus5@gmail.com>
2024-09-22 18:58:31 +08:00
.gitignore first commit 2024-09-22 18:51:12 +08:00
go.mod first commit 2024-09-22 18:51:12 +08:00
go.sum first commit 2024-09-22 18:51:12 +08:00
goh_test.go first commit 2024-09-22 18:51:12 +08:00
goh.go first commit 2024-09-22 18:51:12 +08:00
README.md chore: update readme 2024-09-22 18:58:31 +08:00

goh

use golang to parse html and get node values

Usage


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
}