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 }