-
Notifications
You must be signed in to change notification settings - Fork 0
/
navegador.go
119 lines (99 loc) · 2.48 KB
/
navegador.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package ungo
import (
"bytes"
"encoding/base64"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/url"
"strings"
"time"
)
type HtmlResponse struct {
Html string
Code int
Jar *cookiejar.Jar
URL string
}
type HttpHeader struct {
Host string
ContentType string
UserAgent string
Accept string
AcceptLanguage string
AcceptEncoding string
CacheControl string
Referer string
XRequestedWith string
Origin string
TimeOut int
}
type ResponseJson struct {
DestinationUrl, Status, Url string
Success, AdBlockSpotted bool
}
type Post struct {
Data url.Values
Post bool
}
var (
req *http.Request
err error
Rj ResponseJson
P Post
HH = HttpHeader{
Host: "www.google.com",
UserAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko",
Accept: "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
AcceptLanguage: "de,en;q=0.7,en-us;q=0.3",
AcceptEncoding: "",
CacheControl: "no",
Referer: "www.google.com",
ContentType: "application/x-www-form-urlencoded",
XRequestedWith: "",
Origin: "",
TimeOut: 20,
}
)
func htmlDownload(url string, jar *cookiejar.Jar) HtmlResponse {
client := &http.Client{
Jar: jar,
Timeout: time.Duration(time.Duration(HH.TimeOut) * time.Second), //POG
}
if P.Post == false {
req, err = http.NewRequest("GET", url, nil)
if err != nil {
panic(err)
}
} else {
req, err = http.NewRequest("POST", url, bytes.NewBufferString(P.Data.Encode()))
if err != nil {
panic(err)
}
}
req.Header.Set("Host", HH.Host)
req.Header.Set("Content-Type", HH.ContentType)
req.Header.Set("User-Agent", HH.UserAgent)
req.Header.Set("Accept", HH.Accept)
req.Header.Set("Accept-Language", HH.AcceptLanguage)
req.Header.Set("Accept-Encoding",HH.AcceptEncoding)
req.Header.Set("Cache-Control", HH.CacheControl)
req.Header.Set("Referer", HH.Referer)
req.Header.Set("Origin", HH.Origin)
req.Header.Set("X-Requested-With", HH.XRequestedWith)
resp, err := client.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
panic(err)
}
return HtmlResponse{Html: string(body),Code: resp.StatusCode, Jar: jar, URL: resp.Request.URL.String()}
}
func Base64Decode(b64 string) (string, error) {
b64 = strings.Replace(b64, "=", "", -1) // illegal base64 data at input byte 56
data, _ := base64.StdEncoding.DecodeString(b64) // nobody saw
return string(data), nil
}