-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfree_proxy_list.go
52 lines (40 loc) · 893 Bytes
/
free_proxy_list.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
52
package ipscraper
import (
"errors"
"fmt"
"io"
"net/http"
"strings"
"golang.org/x/net/html"
)
type FreeProxyList struct{}
func NewFreeProxyList() *FreeProxyList {
return &FreeProxyList{}
}
func (f *FreeProxyList) Get() ([]string, error) {
resp, err := http.Get("https://free-proxy-list.net/")
if err != nil {
return nil, fmt.Errorf("http get: %w", err)
}
tokenizer := html.NewTokenizer(resp.Body)
for {
if tokenizer.Next() == html.ErrorToken {
if tokenizer.Err() == io.EOF {
return nil, nil
}
return nil, tokenizer.Err()
}
tag, _ := tokenizer.TagName()
if string(tag) == "textarea" {
list := strings.Split(string(tokenizer.Buffered()), "\n")
if len(list) < 5 {
return nil, errors.New("empty list")
}
const http_ = "http://"
for i := range list {
list[i] = http_ + list[i]
}
return list[3 : len(list)-1], nil
}
}
}