-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathmain.go
53 lines (44 loc) · 900 Bytes
/
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
package main
import (
"github.com/go-crawler/lagou_jobs/pipeline"
"github.com/go-crawler/lagou_jobs/spider"
"log"
"sync"
)
var (
kds = []string{
"golang",
}
citys = []string{
"北京",
"上海",
"广州",
"深圳",
"杭州",
"成都",
}
initResults = []spider.InitResult{}
loopResults = []spider.LoopResult{}
jobPipeline = pipeline.NewJobPipeline()
wg sync.WaitGroup
)
func main() {
for _, kd := range kds {
for _, city := range citys {
wg.Add(1)
go func(city string, kd string) {
defer wg.Done()
initResult, err := spider.InitJobs(city, 1, kd)
if err != nil {
log.Fatalln(err)
}
initResults = append(initResults, initResult...)
loopResults = append(loopResults, spider.LoopJobs())
}(city, kd)
}
}
wg.Wait()
jobPipeline.Push()
log.Printf("Init Results: %v", initResults)
log.Printf("Loop Results: %v", loopResults)
}