aboutsummaryrefslogtreecommitdiff
path: root/tools/charcrawler/crawler/acd_anime.go
diff options
context:
space:
mode:
Diffstat (limited to 'tools/charcrawler/crawler/acd_anime.go')
-rw-r--r--tools/charcrawler/crawler/acd_anime.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/tools/charcrawler/crawler/acd_anime.go b/tools/charcrawler/crawler/acd_anime.go
new file mode 100644
index 0000000..106655d
--- /dev/null
+++ b/tools/charcrawler/crawler/acd_anime.go
@@ -0,0 +1,41 @@
1package crawler
2
3import (
4 "log"
5 "strconv"
6 "strings"
7
8 "github.com/PuerkitoBio/goquery"
9)
10
11type ACDAnimeCrawler struct{}
12
13func (a ACDAnimeCrawler) Name() string {
14 return "ACDAnime"
15}
16
17func (a ACDAnimeCrawler) Crawl(id int) (CharacterData, error) {
18 c := make(CharacterData)
19 doc, err := goquery.NewDocument("http://www.animecharactersdatabase.com/series.php?id=" + strconv.Itoa(id))
20 if err != nil {
21 log.Println(err)
22 return nil, CrawlError
23 }
24 text := doc.Text()
25 if strings.Contains(text, "bad series : try") {
26 return nil, CharacterNotFound
27 }
28 tds := doc.Find("#besttable > table > tbody > tr > td")
29 val, _ := tds.Eq(0).Find("img").Attr("src")
30 c["__thumb"] = val
31 tds.Eq(1).Find("tr").Each(func(i int, s *goquery.Selection) {
32 key := s.Find("th").Text()
33 value := s.Find("td").Text()
34 if key == "Home Page" {
35 val, _ = s.Find("td > a").Attr("href")
36 value = val
37 }
38 c[key] = value
39 })
40 return c, nil
41}