From 479b1c7cd7331b2d7e919fa25efddef48f98523d Mon Sep 17 00:00:00 2001 From: fantasticbin Date: Thu, 4 Apr 2024 08:51:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=88=AC=E8=99=AB=E6=89=A7?= =?UTF-8?q?=E8=A1=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cmd/lib.go | 8 +++----- src/cmd/start.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/cmd/lib.go b/src/cmd/lib.go index eaf7b80..081c73f 100644 --- a/src/cmd/lib.go +++ b/src/cmd/lib.go @@ -47,7 +47,7 @@ func Execute() { } // FindChapterTitle 解析文件夹标题 -func FindChapterTitle(url string, num int) string { +func FindChapterTitle(url string) string { resp, err := http.Get(url) if err != nil { fmt.Println("请求文件夹标题失败:", err) @@ -68,9 +68,8 @@ func FindChapterTitle(url string, num int) string { return "" } - content := string(body) - re := regexp.MustCompile(`\\u7b2c` + strconv.Itoa(num) + `\\u8bdd (.+?)"`) - matches := re.FindAllStringSubmatch(content, -1) + re := regexp.MustCompile(`\\u7b2c` + strconv.Itoa(chapter) + `\\u8bdd (.+?)"`) + matches := re.FindAllStringSubmatch(string(body), -1) if len(matches) == 0 { return "" @@ -84,7 +83,6 @@ func FindChapterTitle(url string, num int) string { replacements := map[string]string{ "?": "?", ":": ":", - "!": "!", } unquoted = strings.TrimSpace(unquoted) for old, re := range replacements { diff --git a/src/cmd/start.go b/src/cmd/start.go index 25c7dea..3c2903d 100644 --- a/src/cmd/start.go +++ b/src/cmd/start.go @@ -13,8 +13,8 @@ import ( ) type Crawler struct { - wg sync.WaitGroup path string + wg sync.WaitGroup } func NewCrawler() *Crawler { @@ -24,7 +24,7 @@ func NewCrawler() *Crawler { func (c *Crawler) Start() { c.path = output if folderTitleUrl != "" { - chapterTitle := FindChapterTitle(folderTitleUrl, chapter) + chapterTitle := FindChapterTitle(folderTitleUrl) title := strings.Join([]string{ "第", strconv.Itoa(chapter),