-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathproxy.go
50 lines (44 loc) · 1.01 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
package main
import (
"github.com/PuerkitoBio/goquery"
"github.com/franela/goreq"
"log"
"time"
)
var proxys []string
func main() {
for _, proxy := range proxys {
res, err := goreq.Request{
Uri: "http://www.baidu.com/",
UserAgent: "Cyeambot",
Proxy: proxy,
Timeout: 5 * time.Second,
}.Do()
goreq.SetConnectTimeout(5 * time.Second)
if err != nil || res.Body == nil {
log.Printf("%s fail.\n", proxy)
} else {
log.Printf("%s success.\n", proxy)
}
}
}
func InitProxys() {
doc, err := goquery.NewDocument("http://proxy.com.ru/list_1.html")
if err != nil {
log.Fatal(err)
}
doc.Find("body > center > font > table:nth-child(1) > tbody > tr > td:nth-child(2) > font > table > tbody > tr").Each(func(i int, s *goquery.Selection) {
if i > 0 {
s.Find("td").Each(func(j int, s *goquery.Selection) {
if j == 1 {
proxys = append(proxys, "http://"+s.Text())
} else if j == 2 {
proxys[i-1] = proxys[i-1] + ":" + s.Text()
}
})
}
})
}
func init() {
InitProxys()
}