MCPcopy
hub / github.com/hwholiday/learning_tools / main

Function main

goquery/main.go:18–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18func main() {
19 res, err := http.Get("https://eosmonitor.io/accounts?page=1")
20 if err != nil {
21 log.Fatal(err)
22 }
23 defer res.Body.Close()
24 if res.StatusCode != 200 {
25 log.Fatalf("status code error: %d %s", res.StatusCode, res.Status)
26 }
27 doc, err := goquery.NewDocumentFromReader(res.Body)
28 if err != nil {
29 log.Fatal(err)
30 }
31 var data []string
32 doc.Find(".common-lsit-data_table").Each(func(i int, s *goquery.Selection) {
33 tdInfo := strings.Split(s.Find("td").Text(), "\n")
34 for _, v := range tdInfo {
35 if len(v)!=0&&len(v)!=12{
36 data = append(data, strings.Replace(v, " ", "", -1))
37 }
38 }
39 })
40 var accounts []Account
41 var account Account
42 for i,v:=range data{
43 switch (i+1) % 4 {
44 case 1://Name
45 account.Name=v
46 break
47 case 2://EOS
48 account.EOS=v
49 break
50 case 3://NETWeight
51 account.NETWeight=v
52 break
53 case 0://CPUWeight
54 account.CPUWeight=v
55 accounts=append(accounts,account)
56 break
57
58 }
59 }
60 fmt.Println(accounts)
61 fmt.Println("结束")
62}

Callers

nothing calls this directly

Calls 2

GetMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected