-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
86 lines (73 loc) · 2.07 KB
/
main.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
package main
import (
"fmt"
"github.com/aws/aws-lambda-go/lambda"
"time"
"strings"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/input"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/proto"
"github.com/go-rod/rod/lib/utils"
"github.com/go-rod/rod/lib/devices"
"sync"
)
func randDevices() devices.Device{
randgen := []devices.Device {devices.GalaxySIII,devices.GalaxyS5,devices.IPadMini,devices.IPad,devices.IPadPro,devices.Nexus10,devices.Nexus7,devices.GalaxyNote3,devices.GalaxyNoteII,devices.Nexus5X,devices.Nexus5,devices.Nexus4,devices.IPhoneX,devices.IPhone6or7or8Plus,devices.IPhone6or7or8,devices.IPhone5orSE}
rand.Seed(time.Now().UnixNano())
randIdx := rand.Intn(len(randgen))
choice := randgen[randIdx]
return choice
}
func start_search()(string) {
url := launcher.New().
Proxy("yourproxy").
//The lambda layers contents use /opt PATH
Bin("/opt/headless-chromium").
Set("--headless").
Set("--single-process").
Set("--v=99").
Set("--enable-webgl").
Set("--disable-dev-shm-usage").
Set("--ignore-gpu-blacklist").
Set("--ignore-certificate-errors").
Set("--allow-running-insecure-content").
Set("-–disable-extensions").
Set("--user-data-dir=/tmp/user-data").
Set("--data-path=/tmp/data-path").
Set("--disable-dev-shm-usage").
Set("--homedir=/tmp").
Set("--disk-cache-dir=/tmp/cache-dir").
Set("--no-sandbox").
Set("--use-gl=osmesa").
Set("--window-size=312,512").
MustLaunch()
browser := rod.New().ControlURL(url).MustConnect()
defer browser.MustClose()
browser.MustIgnoreCertErrors(true)
page := browser.MustPage()
page.MustEmulate(randDevices())
//CODE of search start here...
//CODE of search finish here
new_url := page.MustInfo().URL
return new_url
}
type Request struct {
ID float64 `json:"id"`
value string `json:"value"`
}
type Response struct {
Message string `json:"message"`
Ok bool `json:"ok"`
}
func Handler(request Request) (Response, error) {
//Get the URL of last web loaded
resp := start_search()
return Response{
Message: fmt.Sprintf(resp),
Ok: true,
}, nil
}
func main(){
lambda.Start(Handler)
}