-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathweibo_spider.go
81 lines (69 loc) · 1.79 KB
/
weibo_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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"WeiboSpiderGo/config"
"WeiboSpiderGo/scrapy_rules"
"WeiboSpiderGo/utils"
"fmt"
)
var uidLi = utils.GetTargetUidList()
func scrapyInfomation() {
getInfoC := scrapy_rules.GetDefaultCollector()
getMoreInfoC := scrapy_rules.GetDefaultCollector()
scrapy_rules.SetMoreInfoCallback(getMoreInfoC)
scrapy_rules.SetInfoCallback(getInfoC, getMoreInfoC)
for _, uid := range uidLi {
url := fmt.Sprintf("%s/%s/info", scrapy_rules.BaseUrl, uid)
getInfoC.Visit(url)
}
getInfoC.Wait()
getMoreInfoC.Wait()
}
func scrapyTweet() {
getTweetsC := scrapy_rules.GetDefaultCollector()
getContentSubC := scrapy_rules.GetDefaultCollector()
scrapy_rules.SetFullContentCallback(getContentSubC)
getCommentSubC := scrapy_rules.GetDefaultCollector()
scrapy_rules.SetCommentCallback(getCommentSubC)
scrapy_rules.SetTweetCallback(getTweetsC, getContentSubC, getCommentSubC)
for _, uid := range uidLi {
url := scrapy_rules.GetTweetUrl(uid)
getTweetsC.Visit(url)
}
getTweetsC.Wait()
getContentSubC.Wait()
getCommentSubC.Wait()
}
func scrapyFollow() {
getFollowC := scrapy_rules.GetDefaultCollector()
scrapy_rules.SetFollowCallback(getFollowC)
//read files
for _, uid := range uidLi {
url := scrapy_rules.GetFollowUrl(uid)
getFollowC.Visit(url)
}
getFollowC.Wait()
}
func scrapyFans() {
getFansC := scrapy_rules.GetDefaultCollector()
scrapy_rules.SetFansCallback(getFansC)
for _, uid := range uidLi {
url := scrapy_rules.GetFansUrl(uid)
getFansC.Visit(url)
}
getFansC.Wait()
}
func main() {
if config.Conf.GetBool("SCRAPY_TYPE.Info") {
scrapyInfomation()
}
if config.Conf.GetBool("SCRAPY_TYPE.Follow") {
scrapyFollow()
}
//修复去重问题
if config.Conf.GetBool("SCRAPY_TYPE.Fans") {
scrapyFans()
}
if config.Conf.GetBool("SCRAPY_TYPE.Tweet.Main") {
scrapyTweet()
}
}