package main import ( "fmt" "github.com/antchfx/htmlquery" "net/http" ) func main() { var url string = "https://tieba.baidu.com/f?kw=%C9%EE%BB%A7&fr=ala0&loc=rec" resp, _ := http.Get(url) defer resp.Body.Close() doc,_ := htmlquery.Parse(resp.Body) list := htmlquery.Find(doc, "//a[contains(@class,'j_th_tit')]]") for _,li := range list{ fmt.Printf("%s ",htmlquery.InnerText(li)) fmt.Printf("%s ",htmlquery.SelectAttr(li,"href")) } }