forked from henson/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoubanjia.go
51 lines (45 loc) · 1.27 KB
/
goubanjia.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
package getter
import (
"fmt"
"log"
"regexp"
"strings"
"github.com/PuerkitoBio/goquery"
"github.com/henson/proxypool/pkg/models"
"github.com/parnurzeal/gorequest"
clog "unknwon.dev/clog/v2"
)
// GBJ get ip from goubanjia.com
func GBJ() (result []*models.IP) {
pollURL := "http://www.goubanjia.com/"
resp, _, errs := gorequest.New().Get(pollURL).End()
if errs != nil {
log.Println(errs)
return
}
fmt.Println(resp.Body)
if resp.StatusCode != 200 {
fmt.Println(resp.StatusCode)
fmt.Println(errs)
return
}
doc, err := goquery.NewDocumentFromReader(resp.Body)
resp.Body.Close()
if err != nil {
log.Println(err.Error())
return
}
doc.Find("body > div.container > div.section-header > div.row > div.container-fluid > div.row-fluid > div.span12 > tbody > tr").Each(func(_ int, s *goquery.Selection) {
sf, _ := s.Find(".ip").Html()
tee := regexp.MustCompile("<pstyle=\"display:none;\">.?.?</p>").ReplaceAllString(strings.Replace(sf, " ", "", -1), "")
re, _ := regexp.Compile("\\<[\\S\\s]+?\\>")
ip := models.NewIP()
ip.Data = re.ReplaceAllString(tee, "")
ip.Type1 = s.Find("td:nth-child(3) > a").Text()
ip.Source = "goubanjia"
clog.Info("ip.Data = %s , ip.Type = %s\n", ip.Data, ip.Type1)
result = append(result, ip)
})
clog.Info("GBJ done.")
return
}