forked from go-rod/rod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (33 loc) · 1.24 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
package main
import (
"fmt"
"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/utils"
)
func main() {
// To launch remote browsers, you need a remote launcher service,
// Rod provides a docker image for beginers, make sure have started:
// docker run -p 9222:9222 rodorg/rod
//
// For more information, check the doc of launcher.RemoteLauncher
l := launcher.MustNewRemote("ws://localhost:9222")
// Manipulate flags like the example in examples_test.go
l.Set("window-size", "1920,1080").Delete("any-flag")
browser := rod.New().Client(l.Client()).MustConnect()
// You may want to start a server to watch the screenshots inside the docker
launcher.NewBrowser().Open(browser.ServeMonitor(""))
fmt.Println(
browser.MustPage("https://github.com").MustEval("() => document.title"),
)
utils.Pause()
}
func hardcoreStyle() {
// You can also manually launch a browser in the image:
// docker run -p 9222:9222 rodorg/rod chromium-browser --headless --no-sandbox --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0
u := launcher.MustResolveURL("9222")
browser := rod.New().ControlURL(u).MustConnect()
fmt.Println(
browser.MustPage("https://github.com").MustEval("() => document.title"),
)
}