-
Notifications
You must be signed in to change notification settings - Fork 0
/
shst.go
46 lines (33 loc) · 883 Bytes
/
shst.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
package ungo
import (
"encoding/json"
"io"
"net/http/cookiejar"
"regexp"
"strings"
"time"
)
func Shst(url string) (string, error) {
cookie, _ := cookiejar.New(nil)
HH.Host = "sh.st"
HH.Origin = "http://sh.st"
HH.XRequestedWith = "XMLHttpRequest"
html := htmlDownload(url, cookie)
sessionId := regexp.MustCompile(`sessionId: "(.*)",`)
resutl := sessionId.FindAllStringSubmatch(html.Html, -1)[0:]
HH.Referer = url
time.Sleep(5 * time.Second)
htmlSessionId := htmlDownload("http://sh.st/shortest-url/end-adsession?callback=c&adSessionId="+resutl[0][1], html.Jar)
jsonResult := htmlSessionId.Html[6:]
jsonResult = strings.Replace(jsonResult, ");", "", -1)
dec := json.NewDecoder(strings.NewReader(jsonResult))
for {
err := dec.Decode(&Rj)
if err == io.EOF {
break
} else if err != nil {
return "", err
}
}
return Rj.DestinationUrl, nil
}