forked from henson/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyoudl.go
48 lines (44 loc) · 1.15 KB
/
youdl.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
package getter
import (
"log"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/henson/proxypool/pkg/models"
"github.com/parnurzeal/gorequest"
clog "unknwon.dev/clog/v2"
)
// YDL get ip from youdaili.net
func YDL() (result []*models.IP) {
pollURL := "http://www.youdaili.net/Daili/http/"
_, body, errs := gorequest.New().Get(pollURL).End()
if errs != nil {
log.Println(errs)
return
}
do, err := goquery.NewDocumentFromReader(strings.NewReader(body))
if err != nil {
log.Println(err.Error())
return
}
URL, _ := do.Find("body > div.con.PT20 > div.conl > div.lbtc.l > div.chunlist > ul > li:nth-child(1) > p > a").Attr("href")
_, content, errs := gorequest.New().Get(URL).End()
if errs != nil {
log.Println(errs)
return
}
doc, err := goquery.NewDocumentFromReader(strings.NewReader(content))
if err != nil {
log.Println(err.Error())
return
}
doc.Find(".content p").Each(func(_ int, s *goquery.Selection) {
ip := models.NewIP()
c := strings.Split(s.Text(), "@")
ip.Data = c[0]
ip.Type1 = strings.ToLower(strings.Split(c[1], "#")[0])
ip.Source = "youdl"
result = append(result, ip)
})
clog.Info("YDL done.")
return
}