-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_main.go
45 lines (38 loc) · 898 Bytes
/
example_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
package main
import (
_ "crawler/init"
logger "github.com/alecthomas/log4go"
"os"
"os/signal"
"crawler/downloader/request"
"crawler/spider"
"crawler/schedule"
"fmt"
"crawler/process"
)
func main() {
defer logger.Close()
c := make(chan os.Signal, 1)
logger.Info("Start crawler ...")
startSpider()
signal.Notify(c)
s := <-c
logger.Info("Google Bye, ", s)
}
func startSpider() {
spider := spider.New(&TestPageProcess{
})
spider.Push(&request.Request{
Url:"http://www.baidu.com",
})
spider.Start()
}
type TestPageProcess struct {
}
func (this *TestPageProcess) OnProcess(schedule schedule.Schedule, request *request.Request, response *process.Result) () {
fmt.Printf("%T %+v \n", schedule, schedule)
fmt.Printf("%T %+v \n", request, request)
fmt.Printf("%T %+v \n", response, response)
fmt.Printf("%s \n", response.Status)
fmt.Printf("%s \n", response.BodyString())
}