forked from domainr/whois
-
Notifications
You must be signed in to change notification settings - Fork 0
/
adapter_nr.go
53 lines (45 loc) · 1.07 KB
/
adapter_nr.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
package whois
import (
"bytes"
"net/url"
"strings"
"github.com/andybalholm/cascadia"
"github.com/PuerkitoBio/goquery"
)
type nrAdapter struct {
defaultAdapter
}
func (a *nrAdapter) Prepare(req *Request) error {
labels := strings.SplitN(req.Query, ".", 2)
values := url.Values{}
values.Set("subdomain", labels[0])
values.Set("tld", labels[1])
req.URL = "http://www.cenpac.net.nr/dns/whois.html?" + values.Encode()
req.Body = nil // Always override existing request body
return nil
}
var nrSelectTR = cascadia.MustCompile("hr+table tr:not(:has(tr))")
func (a *nrAdapter) Text(res *Response) ([]byte, error) {
html, err := a.defaultAdapter.Text(res)
if err != nil {
return nil, err
}
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(html))
if err != nil {
return nil, err
}
var buf bytes.Buffer
rows := doc.FindMatcher(nrSelectTR)
rows.Each(func(i int, s *goquery.Selection) {
buf.WriteString(s.Text())
buf.WriteString("\n")
})
return buf.Bytes(), nil
}
func init() {
BindAdapter(
&nrAdapter{},
"cenpac.net.nr",
"www.cenpac.net.nr",
)
}