'golang html.Node.Data container no human characters

i've copied the code below from go programming language book but my output is not the same as in the book the code is as follows :

import (
    "fmt"
    "os"
    "golang.org/x/net/html"
)


func main() {
    doc , err := html.Parse(os.Stdin)
    if err != nil {
        fmt.Fprintf(os.Stderr, "findlinks1: %v\n", err)
        os.Exit(1)
    }

    for _ , link := range visit([]string{} ,doc)  {
        fmt.Println(link);
    }

    

}

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 {
                visit(links,c)
        }
    return links 
}

the data obtained from stdin is in fact the output of another prog that brings the html of a web page the image below shows its output: enter image description here i've added a printf at the begining of visit to see what's going on but i found out that n.Data contains no tag name instead it contains a branch of unreadable characters any help ???



Solution 1:[1]

this program doesn't work because the links variable is copied during the function visit it's true that this new copy points to the same underlying array but any changes assign to it doesn't affect the original so at line

visit(links,c) must be links = visit(links,c)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Drago Ban