golang通过url获取网页html中所有链接地址代码
代码语言:golang
所属分类:其他
代码描述:golang通过url获取网页html中所有链接地址代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
package main import ( "fmt" "net/http" "golang.org/x/net/html" ) func visit(links []string, n *html.Node) []string { if n.Type == html.ElementNode { 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 } func main() { url := "http://ask.bfw.wiki/question-3-0.html" links, err := findLinks(url) if err != nil { fmt.Print.........完整代码请登录后点击上方下载按钮下载查看
网友评论0