Home  >  Article  >  Backend Development  >  How to write link in link

How to write link in link

PHPz
PHPzforward
2024-02-14 20:24:08730browse

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.

Question content

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

Solution

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!

Statement:
This article is reproduced at:stackoverflow.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Golang cannot parse timeNext article:Golang cannot parse time