package main import ( "fmt" "log" "github.com/PuerkitoBio/goquery" ) func main() { doc, err := goquery.NewDocument("https://example.com") if err != nil { log.Fatal(err) } links := doc.Find("a") links.Each(func(i int, s *goquery.Selection) { href, exists := s.Attr("href") if exists { fmt.Println(href) } }) }
package main import ( "fmt" "log" "github.com/PuerkitoBio/goquery" ) func main() { doc, err := goquery.NewDocument("https://example.com") if err != nil { log.Fatal(err) } paragraphs := doc.Find("p") paragraphs.Attr("style", "color:red;") fmt.Println(doc.Html()) }This code retrieves all paragraphs on the webpage using the "Find" method, then sets the "style" attribute for each paragraph to "color:red;" using the "Attr" method. Finally, it prints the modified HTML document to the console using the "Html" method.