https://github.com/bobg/htree
Tools for working with trees of html.Nodes.
https://github.com/bobg/htree
Last synced: 2 months ago
JSON representation
Tools for working with trees of html.Nodes.
- Host: GitHub
- URL: https://github.com/bobg/htree
- Owner: bobg
- License: mit
- Created: 2019-09-12T14:02:35.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-01-27T21:13:26.000Z (about 2 years ago)
- Last Synced: 2024-07-31T20:53:11.191Z (over 1 year ago)
- Language: HTML
- Homepage: https://godoc.org/github.com/bobg/htree
- Size: 87.9 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - htree - Traverse, navigate, filter, and otherwise process trees of [html.Node](https://pkg.go.dev/golang.org/x/net/html#Node) objects. (Text Processing / Markup Languages)
- awesome-go-plus - htree - Traverse, navigate, filter, and otherwise process trees of [html.Node](https://pkg.go.dev/golang.org/x/net/html#Node) objects.  (Text Processing / Markup Languages)
- awesome-go-cn - htree
- awesome-go - htree - Traverse, navigate, filter, and otherwise process trees of [html.Node](https://pkg.go.dev/golang.org/x/net/html#Node) objects. (Text Processing / Markup Languages)
- fucking-awesome-go - htree - Traverse, navigate, filter, and otherwise process trees of 🌎 [html.Node](pkg.go.dev/golang.org/x/net/html#Node) objects. (Text Processing / Markup Languages)
- awesome-go - htree - Traverse, navigate, filter, and otherwise process trees of [html.Node](https://pkg.go.dev/golang.org/x/net/html#Node) objects. (Text Processing / Markup Languages)
- awesome-go-with-stars - htree - 12-08 | (Template Engines / Markup Languages)
- awesome-go-cn - htree
README
# Htree - Go package for working with html.Node trees
[](https://pkg.go.dev/github.com/bobg/htree/v2)
[](https://goreportcard.com/report/github.com/bobg/htree/v2)
[](https://github.com/bobg/htree/actions/workflows/go.yml)
[](https://coveralls.io/github/bobg/htree?branch=master)
[](https://github.com/avelino/awesome-go)
This is htree,
a Go package that helps traverse, navigate, filter, and otherwise process trees of [html.Node](https://pkg.go.dev/golang.org/x/net/html#Node) objects.
## Usage
```go
root, err := html.Parse(input)
if err != nil { ... }
body := htree.FindEl(root, func(n *html.Node) bool {
return n.DataAtom == atom.Body
})
content := htree.FindEl(body, func(n *html.Node) bool {
return n.DataAtom == atom.Div && htree.ElClassContains(n, "content")
})
...etc...
```