Answer the question
In order to leave comments, you need to log in
How to display Titles and Links on the same line?
package main
import (
"fmt"
"log"
"github.com/PuerkitoBio/goquery"
)
type Cyberport struct {
Titles []string
Links []string
}
func main() {
var cyber Cyberport
// получаем ответ на запрос
document, err := goquery.NewDocument("https://www.cybersport.ru/news")
if err != nil {
log.Fatal(err)
}
// получаем текст статьи
document.Find(".cs-news__link").Each(func(index int, item *goquery.Selection) {
text := item.Text()
cyber.Titles = append(cyber.Titles, text)
})
// получаем ссылку на новость
document.Find(".cs-news__text").Each(func(index int, item *goquery.Selection) {
linkTag := item.Find("a")
link, _ := linkTag.Attr("href")
cyber.Links = append(cyber.Links, link)
})
// выводим содержимое
for index, item := range cyber.Links {
fmt.Printf("%d: %v\n", index, item)
}
}
Answer the question
In order to leave comments, you need to log in
for index, item := range cyber.Links {
fmt.Printf("%s: %v\n", cyber.Titles[index], item)
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question