-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy.go
59 lines (55 loc) · 1.51 KB
/
proxy.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
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
const urlApi = "https://ip.jiangxianli.com/api/proxy_ips"
func getProxy() []interface{} {
client := &http.Client{}
req, _ := http.NewRequest("GET", urlApi, nil)
//增加header选项
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36")
//处理返回结果
response, err := client.Do(req)
if err != nil{
fmt.Println(err)
return nil
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
var data interface{}
json.Unmarshal(body,&data)
m := data.(map[string]interface{})
data = m["data"]
m = data.(map[string]interface{})
data = m["data"]
//取出数组
list := data.([]interface{})
return list
}
func refresh(page int) []interface{} {
client := &http.Client{}
refreshUrl := fmt.Sprintf( "%s?page=%d",urlApi,page)
req, _ := http.NewRequest("GET", refreshUrl, nil)
//增加header选项
req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36")
//处理返回结果
response, err := client.Do(req)
if err != nil{
fmt.Println(err)
return nil
}
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
var data interface{}
json.Unmarshal(body,&data)
m := data.(map[string]interface{})
data = m["data"]
m = data.(map[string]interface{})
data = m["data"]
//取出数组
list := data.([]interface{})
return list
}