Home > Article > Backend Development > How to write link in link
When writing an article or adding a link to a web page, it is very important to write the link correctly. Correct writing of links can improve user experience and increase the readability of the article. There are many ways to write links in links. Below I will introduce some common writing methods and precautions. First, you can use the HTML tag to create a link. Within the tag, use the href attribute to specify the target address of the link, and add the link text within the tag. For example: php中文网. This way of writing allows the link to be displayed as a hyperlink on the page, and users can click on the link to jump to the target page.
package main import ( "fmt" "github.com/PuerkitoBio/goquery" "log" ) func main() { var links string = "" doc, err := goquery.NewDocument("https://dev.bolshoi.ru/visit/buyingnew/") if err != nil { log.Fatal(err) } doc.Find("a:contains(\"График предварительной продажи билетов на декабрь 2023\")").Each(func(i int, s *goquery.Selection) { link, _ := s.Attr("href") fmt.Printf(link) }) }
I've just started learning the language and I don't quite understand what needs to be done
Here's how to assign a link value to an external link variable:
package main import ( "fmt" "log" "net/http" "github.com/PuerkitoBio/goquery" ) func main() { var links string = "" resp, err := http.Get("https://dev.bolshoi.ru/visit/buyingnew/") if err != nil { log.Fatal(err) } doc, err := goquery.NewDocumentFromReader(resp.Body) if err != nil { log.Fatal(err) } doc.Find("a:contains(\"График предварительной продажи билетов на декабрь 2023\")").Each(func(i int, s *goquery.Selection) { link, _ := s.Attr("href") fmt.Println(link) links = link }) fmt.Println(links) }
If there are multiple links, you can make a slice:
links := []string{} //... doc.Find("a:contains(\"График предварительной продажи билетов на декабрь 2023\")").Each(func(i int, s *goquery.Selection) { link, _ := s.Attr("href") fmt.Println(link) links = append(links, link) }) fmt.Println(links)
The above is the detailed content of How to write link in link. For more information, please follow other related articles on the PHP Chinese website!