-
Notifications
You must be signed in to change notification settings - Fork 0
/
ip66.go
49 lines (44 loc) · 1.45 KB
/
ip66.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
package ip66
import (
"fmt"
"github.com/PuerkitoBio/goquery"
logger "github.com/sirupsen/logrus"
"github.com/wuchunfu/IpProxyPool/fetcher"
"github.com/wuchunfu/IpProxyPool/models/ipModel"
"github.com/wuchunfu/IpProxyPool/util"
"strconv"
"strings"
)
func Ip66() []*ipModel.IP {
logger.Info("[66ip] fetch start")
list := make([]*ipModel.IP, 0)
indexUrl := "http://www.66ip.cn"
//fetchIndex := fetcher.Fetch(indexUrl)
//pageNum := fetchIndex.Find("#PageList > a:nth-child(12)").Text()
//num, _ := strconv.Atoi(pageNum)
//fmt.Println("=====")
//fmt.Println(num)
for i := 1; i <= 100; i++ {
url := fmt.Sprintf("%s/%d.html", indexUrl, i)
fetch := fetcher.Fetch(url)
fetch.Find("table > tbody").Each(func(i int, selection *goquery.Selection) {
selection.Find("tr").NextAll().Each(func(i int, selection *goquery.Selection) {
proxyIp := strings.TrimSpace(selection.Find("td:nth-child(1)").Text())
proxyPort := strings.TrimSpace(selection.Find("td:nth-child(2)").Text())
proxyLocation := strings.TrimSpace(selection.Find("td:nth-child(3)").Text())
ip := new(ipModel.IP)
ip.ProxyHost = proxyIp
ip.ProxyPort, _ = strconv.Atoi(proxyPort)
ip.ProxyType = "http"
ip.ProxyLocation = proxyLocation
ip.ProxySpeed = 100
ip.ProxySource = "http://www.66ip.cn"
ip.CreateTime = util.FormatDateTime()
ip.UpdateTime = util.FormatDateTime()
list = append(list, ip)
})
})
}
logger.Info("[66ip] fetch done")
return list
}