-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproxy.go
More file actions
46 lines (44 loc) · 1.04 KB
/
proxy.go
File metadata and controls
46 lines (44 loc) · 1.04 KB
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 main
import (
"context"
"github.com/scrapeless-ai/sdk-go/scrapeless"
"github.com/scrapeless-ai/sdk-go/scrapeless/log"
proxy2 "github.com/scrapeless-ai/sdk-go/scrapeless/services/proxies"
"io"
"net/http"
"net/url"
)
func main() {
client := scrapeless.New(scrapeless.WithProxy())
defer client.Close()
proxy, err := client.Proxy.Proxy(context.TODO(), proxy2.ProxyActor{
Country: "US",
SessionDuration: 180,
SessionId: "YOUR SESSION ID",
Gateway: "YOU GATEWAY",
})
if err != nil {
panic(err)
}
log.Info(proxy)
parse, err := url.Parse(proxy)
if err != nil {
panic(err)
}
request, err := http.NewRequest(http.MethodGet, "https://www.google.com", nil)
if err != nil {
panic(err)
}
request.Header.Set("HEADER KEY", "HEADER VALUE")
clientHttp := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(parse)}}
resp, err := clientHttp.Do(request)
defer resp.Body.Close()
if err != nil {
panic(err)
}
body, err := io.ReadAll(resp.Body)
if err != nil {
panic(err)
}
log.Info(string(body))
}