package recon import ( "strings" "golang.org/x/net/html" ) type htmlNode struct { tag string attrs map[string]string children []*htmlNode } func (n *htmlNode) attr(key string) string { if n == nil || n.attrs == nil { return "" } return n.attrs[key] } func parseHTMLTree(body string) (*html.Node, error) { return html.Parse(strings.NewReader(body)) } func toHTMLNode(n *html.Node) *htmlNode { if n == nil { return nil } out := &htmlNode{tag: n.Data, attrs: map[string]string{}} for _, a := range n.Attr { out.attrs[a.Key] = a.Val } for c := n.FirstChild; c != nil; c = c.NextSibling { if child := toHTMLNode(c); child != nil { out.children = append(out.children, child) } } return out }