// Go with Goquery
package main
import (
"fmt"
"log"
"strings"
"github.com/PuerkitoBio/goquery"
)
func main() {
htmlDoc := `
`
doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlDoc))
if err != nil {
log.Fatal(err)
}
var links []string
// The core command to find all 'a' tags and extract the 'href'
doc.Find("a[href]").Each(func(i int, s *goquery.Selection) {
// For each item found, get the href attribute
href, exists := s.Attr("href")
if exists {
links = append(links, href)
}
})
// Print all the collected links
for _, link := range links {
fmt.Println(link)
}
}