Skip to content

Instantly share code, notes, and snippets.

@Adron
Created July 3, 2019 03:12
Show Gist options
  • Save Adron/894f3e63e426793adfb2ec59ad04cccb to your computer and use it in GitHub Desktop.
Save Adron/894f3e63e426793adfb2ec59ad04cccb to your computer and use it in GitHub Desktop.
The Visit Function.
func visit(links []string, n *html.Node) []string {
if n.Type == html.ElementNode && n.Data == "a" {
for _, a := range n.Attr {
if a.Key == "href" {
links = append(links, a.Val)
}
}
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
links = visit(links, c)
}
return links
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment