Skip to content

Instantly share code, notes, and snippets.

@limboinf
Created December 17, 2017 10:14
Show Gist options
  • Save limboinf/048f06c4ec2eeed8cd1116f57e640df3 to your computer and use it in GitHub Desktop.
Save limboinf/048f06c4ec2eeed8cd1116f57e640df3 to your computer and use it in GitHub Desktop.
Get the latest topics of studygolang.com
package main
import (
"log"
"time"
"github.com/PuerkitoBio/goquery"
"github.com/briandowns/spinner"
)
const (
host = "http://studygolang.com"
topic = "http://studygolang.com/topics"
)
func main() {
// build and start new spinner
s := spinner.New(spinner.CharSets[35], 100 * time.Millisecond)
s.Start()
doc, err := goquery.NewDocument(topic)
if err != nil {
log.Fatal(err)
}
doc.Find(".topics .topic").Each(func (i int, cntSelection *goquery.Selection) {
item := cntSelection.Find(".title a")
title := item.Text()
link, _ := item.Attr("href")
link = host + link
log.Println("[", i+1, "]", title, link)
})
s.Stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment