Created
December 17, 2017 10:14
-
-
Save limboinf/048f06c4ec2eeed8cd1116f57e640df3 to your computer and use it in GitHub Desktop.
Get the latest topics of studygolang.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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