package main import ( "fmt" "github.com/PuerkitoBio/goquery" ) func main() { doc, err := goquery.NewDocument("https://www.google.com/") if err != nil { panic(err) } title := doc.Find("title").Text() fmt.Println(title) }
package main import ( "fmt" "github.com/PuerkitoBio/goquery" ) func main() { doc, err := goquery.NewDocument("https://en.wikipedia.org/wiki/Go_(programming_language)") if err != nil { panic(err) } doc.Find("#toc").Children().Each(func(i int, s *goquery.Selection) { fmt.Printf("%d: %s\n", i, s.Text()) }) }In this example, the Selection package is used to extract the table of contents from a Wikipedia page using a selector and print out each item in the list. Overall, the Selection package provides a powerful and flexible tool for developers looking to manipulate HTML documents in Go.