⎗ ✓ 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//go get github.com/PuerkitoBio/goquery package main import ( "fmt" "github.com/PuerkitoBio/goquery" "regexp" "sync" "log" ) func main() { url := "https://13dl.me/list/popular/" var count int = 0 var mu sync.Mutex message := make(chan string) for { var ta_url string ta_url = url go func(){ doc, err := goquery.NewDocument(ta_url) if err != nil { log.Println("err",err) } atag := doc.Find("a") re1 := regexp.MustCompile(`^Home`) re2 := regexp.MustCompile(`^Popular Manga`) re3 := regexp.MustCompile(`^Page\s\d*`) re4 := regexp.MustCompile(`^Prev`) re5 := regexp.MustCompile(`^Newest`) re0 := regexp.MustCompile(`^Next`) var title string var flag bool atag.Each(func(i int, s *goquery.Selection){ str1, _ := s.Attr("title") str2, _ := s.Attr("href") title = str1 if re0.MatchString(title) == true { message <- str2 flag = true } else if ( title == "" || re1.MatchString(title) == true || re2.MatchString(title) == true || re3.MatchString(title) == true || re4.MatchString(title) == true || re4.MatchString(title) == true || re5.MatchString(title) == true ) { } else { mu.Lock() count ++ // fmt.Println(count, title) mu.Unlock() } }) atag = nil doc = nil if flag != true { message <- "" } }() msg := <-message fmt.Println(count,msg) if msg != "" { url = msg } else { break } } }