这里直接贴代码
package main
import (
	"fmt"
	"github.com/PuerkitoBio/goquery"
	"log"
	"strings"
)
type HotsContent struct {
	num     int
	content string
	comment string
	url     string
}
func main() {
	fmt.Println("开始爬取糗事百科热点笑话...")
	js, err := goquery.NewDocument("https://www.qiushibaike.com/hot/")
	if err != nil {
		log.Fatal(err)
	}
	js.Find("#content-left .article").Each(func(i int, contentSelection *goquery.Selection) {
		//先判断是否有图片
		img, _ := contentSelection.Find(".thumb a").Attr("href")
		if len(img) == 0 {
			hotsArt := HotsContent{}
			content := contentSelection.Find(".content span").Text()
			url, _ := contentSelection.Find(".contentHerf").Attr("href")
			comment_name := contentSelection.Find(".cmtMain .cmt-name").Text()
			comment_cont := contentSelection.Find(".cmtMain .main-text").Text()
			hotsArt.num = i + 1
			hotsArt.url = "https://www.qiushibaike.com" + url
			hotsArt.content = strings.Replace(content, "\n", "", -1)
			hotsArt.comment = strings.Replace(comment_name+comment_cont, "\n", "", -1)
			fmt.Println("第", hotsArt.num, "个笑话:")
			fmt.Println("\t", hotsArt.content)
			fmt.Println("\t 最热评论:" + hotsArt.comment)
			fmt.Println("\t 地址", hotsArt.url)
			fmt.Println("======================================================")
		}
	})
}
谢绝吐槽,写着练手玩玩的
|      1jjianwen68      2017-09-05 09:35:19 +08:00 几年前用过 goquery,挺好用 | 
|  |      2zbl430 OP @jjianwen68 还可以 | 
|  |      3qlbr      2017-09-05 10:17:22 +08:00 第一次见到活的 go 语言, 原来是酱紫的 | 
|  |      4pathletboy      2017-09-05 10:21:59 +08:00 你已经留了一个坑,结构体字段名首字母最好大写,避免将来踩坑。 | 
|  |      5zbl430 OP @pathletboy 有道理,记住了 | 
|  |      6yigemeirenyongde      2017-09-05 14:40:51 +08:00 还在入门 go,前端转 go | 
|  |      7lixuda      2017-09-05 14:44:53 +08:00 感觉 go 越来越牛 | 
|      8polaris1119      2017-09-05 14:49:54 +08:00 go 发展还是挺猛的 | 
|      9Akkuman      2017-09-05 16:52:56 +08:00 go 写了几个网站,还行 |