forked from henson/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkuaidl.go
39 lines (35 loc) · 981 Bytes
/
kuaidl.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
package getter
import (
"github.com/Aiicy/htmlquery"
"github.com/henson/proxypool/pkg/models"
clog "unknwon.dev/clog/v2"
)
// KDL get ip from kuaidaili.com
func KDL() (result []*models.IP) {
pollURL := "http://www.kuaidaili.com/free/inha/"
doc, _ := htmlquery.LoadURL(pollURL)
trNode, err := htmlquery.Find(doc, "//table[@class='table table-bordered table-striped']//tbody//tr")
if err != nil {
clog.Warn(err.Error())
}
for i := 0; i < len(trNode); i++ {
tdNode, _ := htmlquery.Find(trNode[i], "//td")
ip := htmlquery.InnerText(tdNode[0])
port := htmlquery.InnerText(tdNode[1])
Type := htmlquery.InnerText(tdNode[3])
speed := htmlquery.InnerText(tdNode[5])
IP := models.NewIP()
IP.Data = ip + ":" + port
if Type == "HTTPS" {
IP.Type1 = "https"
IP.Type2 = "https"
} else if Type == "HTTP" {
IP.Type1 = "http"
}
IP.Source = "KDL"
IP.Speed = extractSpeed(speed)
result = append(result, IP)
}
clog.Info("[kuaidaili] done")
return
}