-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.go
42 lines (37 loc) · 1.13 KB
/
fetch.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
package godc
import (
"io"
"net/http"
"strconv"
"time"
)
func fetchURL(URL string) io.ReadCloser {
client := &http.Client{
Timeout: time.Second * 30,
}
req, err := http.NewRequest("GET", URL, nil)
if err != nil {
return nil
}
req.Header.Set("Host", "m.dcinside.com")
req.Header.Set("User-Agent", "Mozilla/5.0 (Linux; Android 7.0; PLUS Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.98 Mobile Safari/537.36")
req.Header.Set("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
req.Header.Set("Accept-Language", "ko-KR,ko;q=0.8,en-US;q=0.5,en;q=0.3")
req.Header.Set("Accept-Encoding", "utf-8")
req.Header.Set("Connection", "keep-alive")
req.Header.Set("Upgrade-Insecure-Requests", "1")
req.Header.Set("Pragma", "no-cache")
req.Header.Set("Cache-Control", "no-cache")
resp, err := client.Do(req)
if err != nil {
return nil
}
return resp.Body
}
func fetchRawArticleList(gallCode string, page int, recommend bool) io.ReadCloser {
rec := ""
if recommend {
rec = "&recommend=1"
}
return fetchURL("https://m.dcinside.com/board/" + gallCode + "?page=" + strconv.Itoa(page) + rec)
}