Created
July 3, 2019 03:12
-
-
Save Adron/894f3e63e426793adfb2ec59ad04cccb to your computer and use it in GitHub Desktop.
The Visit Function.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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