forked from 15921483570/wechat_spider
-
Notifications
You must be signed in to change notification settings - Fork 2
/
spider.go
58 lines (45 loc) · 1002 Bytes
/
spider.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
package wechat_spider
import (
"log"
"net/http"
"github.com/elazarl/goproxy"
)
type spider struct {
proxy *goproxy.ProxyHttpServer
config *Config
}
var _spider = newSpider()
func Regist(proc Processor) {
_spider.Regist(proc)
}
func Run(port string) {
_spider.Run(port)
}
func newSpider() *spider {
sp := &spider{}
sp.proxy = goproxy.NewProxyHttpServer()
sp.proxy.OnRequest().HandleConnect(goproxy.AlwaysMitm)
return sp
}
func (s *spider) Regist(proc Processor) {
s.proxy.OnResponse().DoFunc(ProxyHandle(proc))
}
func (s *spider) Run(port string) {
log.Println("server will at port:" + port)
log.Fatal(http.ListenAndServe(":"+port, s.proxy))
}
var (
rootConfig = &Config{
Verbose: false,
AutoScroll: false,
Metrics: false,
}
)
type Config struct {
Verbose bool // Debug
AutoScroll bool // Auto scroll page to hijack all history articles
Metrics bool // Get the metrics:such as Comments and Favors
}
func InitConfig(conf *Config) {
rootConfig = conf
}