blob: c697b43a18036b8c847a3e4458be4825f4c7a1e8 (
plain)
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
|
package crawler
import (
"log"
"strconv"
"strings"
"github.com/PuerkitoBio/goquery"
)
type ACDAnimeCrawler struct{}
func (a ACDAnimeCrawler) Name() string {
return "ACDAnime"
}
func (a ACDAnimeCrawler) Crawl(id int) (CharacterData, error) {
c := make(CharacterData)
doc, err := goquery.NewDocument("http://www.animecharactersdatabase.com/series.php?id=" + strconv.Itoa(id))
if err != nil {
log.Println(err)
return nil, CrawlError
}
text := doc.Text()
if strings.Contains(text, "bad series : try") {
return nil, CharacterNotFound
}
if strings.Contains(text, "Your IP has been blocked") {
return nil, Banned
}
tds := doc.Find("#besttable > table > tbody > tr > td")
val, _ := tds.Eq(0).Find("img").Attr("src")
c["__thumb"] = val
tds.Eq(1).Find("tr").Each(func(i int, s *goquery.Selection) {
key := s.Find("th").Text()
value := s.Find("td").Text()
if key == "Home Page" {
val, _ = s.Find("td > a").Attr("href")
value = val
}
c[key] = value
})
return c, nil
}
|