func main() { s := "http://quote.eastmoney.com/stocklist.html" x, err := goquery.ParseUrl(s) if err != nil { panic(err) } nodes := x.Find("#quotesearch ul li") arr := nodes.HtmlAll() for _, item := range arr { fmt.Println(item) } }
func FetchAllStockCode(fname string) { var url = "http://quote.eastmoney.com/stocklist.html" htm, err := goquery.ParseUrl(url) if err != nil { fmt.Println("Error:", err) } quote := htm.Find("div.quotebody") links := quote.Find("a") lns := links.Attrs("href") f, err := os.OpenFile(fname, os.O_CREATE|os.O_WRONLY, os.ModePerm) defer f.Close() w := csv.NewWriter(f) for i := range lns { herf := lns[i] if strings.HasSuffix(herf, ".html") && strings.Contains(herf, "") { fmt.Println(herf) ix1 := strings.LastIndex(herf, "/") ix2 := strings.Index(herf, ".html") s := &Stock{} s.Code = herf[ix1+1 : ix2][2:] s.Area = herf[ix1+1 : ix2][:2] getStockInfoFromSina(s) w.Write([]string{s.Code, s.Area, s.Name}) // f.WriteString(code+"\r\n") // fmt.Println(herf[27:35]) } } w.Flush() f.Close() }