forked from xiaofei-ya/proxypool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb_fanqiangdang.go
97 lines (86 loc) · 2.25 KB
/
web_fanqiangdang.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package getter
import (
"fmt"
"github.com/xiaofei-ya/proxypool/log"
"strings"
"sync"
"github.com/xiaofei-ya/proxypool/pkg/proxy"
"github.com/xiaofei-ya/proxypool/pkg/tool"
"github.com/gocolly/colly"
)
func init() {
Register("web-fanqiangdang", NewWebFanqiangdangGetter)
}
type WebFanqiangdang struct {
c *colly.Collector
Url string
results proxy.ProxyList
}
func NewWebFanqiangdangGetter(options tool.Options) (getter Getter, err error) {
urlInterface, found := options["url"]
if found {
url, err := AssertTypeStringNotNull(urlInterface)
if err != nil {
return nil, err
}
return &WebFanqiangdang{
c: colly.NewCollector(),
Url: url,
}, nil
}
return nil, ErrorUrlNotFound
}
func (w *WebFanqiangdang) Get() proxy.ProxyList {
w.results = make(proxy.ProxyList, 0)
w.c.OnHTML("td.t_f", func(e *colly.HTMLElement) {
innerHTML, err := e.DOM.Html()
if err != nil {
return
}
if strings.Contains(innerHTML, "data-cfemail") {
decoded, err := tool.CFEmailDecode(tool.GetCFEmailPayload(innerHTML))
if err == nil {
e.Text = strings.ReplaceAll(e.Text, "[email protected]", decoded)
}
}
w.results = append(w.results, FuzzParseProxyFromString(e.Text)...)
subUrls := urlRe.FindAllString(e.Text, -1)
for _, url := range subUrls {
w.results = append(w.results, (&Subscribe{Url: url}).Get()...)
}
})
w.c.OnHTML("th.new>a[href]", func(e *colly.HTMLElement) {
url := e.Attr("href")
if url == "javascript:;" {
return
}
url, err := tool.CFScriptRedirect(url)
if err == nil && url[0] == '/' {
url = "https://fanqiangdang.com" + url
}
if strings.HasPrefix(url, "https://fanqiangdang.com/thread") {
_ = e.Request.Visit(url)
}
})
w.results = make(proxy.ProxyList, 0)
err := w.c.Visit(w.Url)
if err != nil {
_ = fmt.Errorf("%s", err.Error())
}
return w.results
}
func (w *WebFanqiangdang) Get2ChanWG(pc chan proxy.Proxy, wg *sync.WaitGroup) {
defer wg.Done()
nodes := w.Get()
log.Infoln("STATISTIC: Fanqiangdang\tcount=%d\turl=%s\n", len(nodes), w.Url)
for _, node := range nodes {
pc <- node
}
}
func (w *WebFanqiangdang) Get2Chan(pc chan proxy.Proxy) {
nodes := w.Get()
log.Infoln("STATISTIC: Fanqiangdang\tcount=%d\turl=%s\n", len(nodes), w.Url)
for _, node := range nodes {
pc <- node
}
}