-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (48 loc) · 1.07 KB
/
main.go
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
package main
import (
"fmt"
"io/ioutil"
"net/http"
"regexp"
)
func check(e error) {
if e != nil {
panic(e)
}
}
type ComicSite struct {
MainPageUrl string
}
func (cs ComicSite) GetComicMainPageUrl(comicId int) string {
return fmt.Sprintf("%s/cn/s/%d/", cs.MainPageUrl, comicId)
}
func main() {
comicSite := ComicSite{
MainPageUrl: "https://*****",
}
// 获取漫画页
comicMainPageUrl := comicSite.GetComicMainPageUrl(282526)
res, err := http.Get(comicMainPageUrl)
check(err)
data, err := ioutil.ReadAll(res.Body)
check(err)
html := string(data)
// 匹配标题
titleR, err := regexp.Compile(`<title>(.+?)</title>`)
check(err)
titleMatches := titleR.FindStringSubmatch(html)
if titleMatches == nil {
panic("comic title not found")
}
title := titleMatches[1]
fmt.Println(title)
// 匹配下载 ID
downloadR, err := regexp.Compile(`cn/(\d+)/1.(jpg|png)`)
check(err)
downloadMatches := downloadR.FindStringSubmatch(html)
if downloadMatches == nil {
panic("download id not found")
}
downloadIdStr := downloadMatches[1]
fmt.Println(downloadIdStr)
}