-
Notifications
You must be signed in to change notification settings - Fork 4
/
linkshell.go
108 lines (87 loc) · 3.52 KB
/
linkshell.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package godestone
import (
"strconv"
"github.com/gocolly/colly/v2"
"github.com/xivapi/godestone/v2/data/gcrank"
)
func (s *Scraper) buildLinkshellCollector(ls *Linkshell) *colly.Collector {
c := colly.NewCollector(
colly.UserAgent(s.meta.UserAgentDesktop),
colly.IgnoreRobotsTxt(),
colly.Async(),
)
basicSelectors := s.getLinkshellSelectors().Basic
c.OnHTML(basicSelectors.Name.Selector, func(e *colly.HTMLElement) {
ls.Name = basicSelectors.Name.Parse(e)[0]
})
ls.Members = []*LinkshellMember{}
membersSelectors := s.getLinkshellSelectors().Members
c.OnHTML(membersSelectors.Root.Selector, func(container *colly.HTMLElement) {
nextURI := membersSelectors.ListNextButton.ParseThroughChildren(container)[0]
container.ForEach(membersSelectors.Entry.Root.Selector, func(i int, e *colly.HTMLElement) {
member := &LinkshellMember{
Avatar: membersSelectors.Entry.Avatar.ParseThroughChildren(e)[0],
Name: membersSelectors.Entry.Name.ParseThroughChildren(e)[0],
Rank: gcrank.Parse(membersSelectors.Entry.Rank.ParseThroughChildren(e)[0]),
RankIcon: membersSelectors.Entry.RankIcon.ParseThroughChildren(e)[0],
LinkshellRank: membersSelectors.Entry.LinkshellRank.ParseThroughChildren(e)[0],
LinkshellRankIcon: membersSelectors.Entry.LinkshellRankIcon.ParseThroughChildren(e)[0],
}
worldDC := membersSelectors.Entry.Server.ParseThroughChildren(e)
member.World = worldDC[0]
member.DC = worldDC[1]
idStr := membersSelectors.Entry.ID.ParseThroughChildren(e)[0]
id, err := strconv.ParseUint(idStr, 10, 32)
if err == nil {
member.ID = uint32(id)
}
ls.Members = append(ls.Members, member)
})
if nextURI != "javascript:void(0);" {
container.Request.Visit(nextURI)
}
})
return c
}
func (s *Scraper) buildCWLSCollector(cwls *CWLS) *colly.Collector {
c := colly.NewCollector(
colly.UserAgent(s.meta.UserAgentDesktop),
colly.IgnoreRobotsTxt(),
colly.Async(),
)
basicSelectors := s.getCWLSSelectors().Basic
c.OnHTML(basicSelectors.Name.Selector, func(e *colly.HTMLElement) {
cwls.Name = basicSelectors.Name.Parse(e)[0]
})
c.OnHTML(basicSelectors.DC.Selector, func(e *colly.HTMLElement) {
cwls.DC = basicSelectors.DC.Parse(e)[0]
})
cwls.Members = []*CWLSMember{}
membersSelectors := s.getCWLSSelectors().Members
c.OnHTML(membersSelectors.Root.Selector, func(container *colly.HTMLElement) {
nextURI := membersSelectors.ListNextButton.ParseThroughChildren(container)[0]
container.ForEach(membersSelectors.Entry.Root.Selector, func(i int, e *colly.HTMLElement) {
member := &CWLSMember{
Avatar: membersSelectors.Entry.Avatar.ParseThroughChildren(e)[0],
Name: membersSelectors.Entry.Name.ParseThroughChildren(e)[0],
Rank: gcrank.Parse(membersSelectors.Entry.Rank.ParseThroughChildren(e)[0]),
RankIcon: membersSelectors.Entry.RankIcon.ParseThroughChildren(e)[0],
LinkshellRank: membersSelectors.Entry.LinkshellRank.ParseThroughChildren(e)[0],
LinkshellRankIcon: membersSelectors.Entry.LinkshellRankIcon.ParseThroughChildren(e)[0],
}
worldDC := membersSelectors.Entry.Server.ParseThroughChildren(e)
member.World = worldDC[0]
member.DC = worldDC[1]
idStr := membersSelectors.Entry.ID.ParseThroughChildren(e)[0]
id, err := strconv.ParseUint(idStr, 10, 32)
if err == nil {
member.ID = uint32(id)
}
cwls.Members = append(cwls.Members, member)
})
if nextURI != "javascript:void(0);" {
container.Request.Visit(nextURI)
}
})
return c
}