-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscrapeGuild.go
64 lines (52 loc) · 1.76 KB
/
scrapeGuild.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
package scraper
import (
"net/http"
"strconv"
"github.com/gocolly/colly/v2"
"bdo-rest-api/cache"
"bdo-rest-api/models"
"bdo-rest-api/utils"
)
func scrapeGuild(body *colly.HTMLElement, region, guildName string) {
status := http.StatusNotFound
guildProfile := models.GuildProfile{
Region: region,
}
body.ForEachWithBreak(".guild_name p", func(_ int, e *colly.HTMLElement) bool {
guildProfile.Name = e.Text
status = http.StatusOK
return false
})
body.ForEachWithBreak(".line_list.mob_none .desc", func(_ int, e *colly.HTMLElement) bool {
createdOn := utils.ParseDate(e.Text)
guildProfile.CreatedOn = &createdOn
return false
})
body.ForEachWithBreak(".line_list:not(.mob_none) li:nth-child(2) .desc .text a", func(_ int, e *colly.HTMLElement) bool {
guildProfile.Master = &models.Profile{
FamilyName: e.Text,
ProfileTarget: extractProfileTarget(e.Attr("href")),
}
return false
})
body.ForEachWithBreak(".line_list:not(.mob_none) li:nth-child(3) em", func(_ int, e *colly.HTMLElement) bool {
population, _ := strconv.Atoi(e.Text)
guildProfile.Population = uint8(population)
return false
})
body.ForEachWithBreak(".line_list:not(.mob_none) li:last-child .desc", func(_ int, e *colly.HTMLElement) bool {
text := utils.RemoveExtraSpaces(e.Text)
if text != "None" && text != "N/A" && text != "없음" {
guildProfile.Occupying = text
}
return false
})
body.ForEach(".box_list_area .adventure_list_table a", func(_ int, e *colly.HTMLElement) {
member := models.Profile{
FamilyName: e.Text,
ProfileTarget: extractProfileTarget(e.Attr("href")),
}
guildProfile.Members = append(guildProfile.Members, member)
})
cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId"))
}