-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
89 lines (78 loc) · 1.64 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
"sync"
)
const MAXGRT = 50
var (
cookie = "" //
url = "http://kjyy.ccnu.edu.cn/ClientWeb/pro/ajax/data/searchAccount.aspx?type=logonname&ReservaApply=ReservaApply&term="
cli http.Client
task chan string
wg sync.WaitGroup
data cmap
)
type cmap struct {
l sync.RWMutex
data map[string]string
}
type Info struct {
Id string `json:"id"`
Pid string `json:"Pid"`
Name string `json:"name"`
Label string `json:"label"`
SzLogonName string `json:"szLogonName"`
SzHandPhone string `json:"szHandPhone"`
SzTel string `json:"szTel"`
SzEmail string `json:"szEmail"`
}
func main() {
data.data = make(map[string]string)
var begin, end int
cli = http.Client{}
fmt.Println("from? to?")
fmt.Scanf("%d %d", &begin, &end)
task = make(chan string, 1000)
go func(){for begin <= end {
task <- strconv.Itoa(begin)
begin++
}}()
wg.Add(MAXGRT)
for i := 1; i <= MAXGRT; i++ {
go worm()
}
close(task)
wg.Wait()
tmp, _ := json.Marshal(data.data)
out, _ := os.OpenFile("data.json", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0777)
out.Write(tmp)
out.Close()
}
func worm() {
for id := range task {
req, _ := http.NewRequest("GET", url+id, nil)
req.Header = map[string][]string{
"Cookie": {cookie},
}
res, _ := cli.Do(req)
var tmp []Info
content, _ := io.ReadAll(res.Body)
json.Unmarshal(content, &tmp)
if len(tmp) > 0 {
tmp[0].Pid = id
tmp[0].SzLogonName = id
data.l.Lock()
data.data[id] = tmp[0].Name
data.l.Unlock()
fmt.Println(tmp[0])
} else {
fmt.Println(id + " nil")
}
}
wg.Done()
}