-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
60 lines (53 loc) · 1.1 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
57
58
59
60
package main
import (
"./actresses"
"./videos"
"flag"
"fmt"
"io"
"io/ioutil"
"net/http"
)
type DmmVideosListError struct {
Error string `json:"error"`
ErrorNo string `json:"status"`
}
func main () {
var url, mode string
flag.StringVar(&url,"dmmurl", "", "dmm 列表頁網址")
flag.StringVar(&mode, "mode", "videos", "解析模式")
flag.Parse()
// 判斷網址參數
if len(url) == 0 {
panic("網址不得為空")
}
// 建立 http 連線以便取得網頁內容
c := http.Client{}
var resp io.Reader
req, _ := http.NewRequest("GET", url, resp)
req.AddCookie(&http.Cookie{
Name: "age_check_done",
Value: "1",
})
out, err2 := c.Do(req)
// 如果發生錯誤時
if err2 != nil {
fmt.Printf(">>> Error: %s\n", err2)
return
}
//
// 不是 200 時
if out.StatusCode != 200 {
fmt.Printf(">>> Error (HTTP): %d\n", out.StatusCode)
responseContent, _ := ioutil.ReadAll(out.Body)
fmt.Printf(string(responseContent))
return
}
defer out.Body.Close()
switch mode {
case "videos":
videos.Parse(out.Body)
case "actresses":
actresses.Parse(out.Body)
}
}