forked from chromedp/examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
41 lines (33 loc) · 1.04 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
// Command remote is a chromedp example demonstrating how to connect to an
// existing Chrome DevTools instance using a remote WebSocket URL.
package main
import (
"context"
"flag"
"log"
"github.com/chromedp/chromedp"
)
var flagDevToolWsUrl = flag.String("devtools-ws-url", "", "DevTools WebSsocket URL")
func main() {
flag.Parse()
if *flagDevToolWsUrl == "" {
log.Fatal("must specify -devtools-ws-url")
}
// create allocator context for use with creating a browser context later
allocatorContext, cancel := chromedp.NewRemoteAllocator(context.Background(), *flagDevToolWsUrl)
defer cancel()
// create context
ctxt, cancel := chromedp.NewContext(allocatorContext)
defer cancel()
// run task list
var body string
if err := chromedp.Run(ctxt,
chromedp.Navigate("https://duckduckgo.com"),
chromedp.WaitVisible("#logo_homepage_link"),
chromedp.OuterHTML("html", &body),
); err != nil {
log.Fatalf("Failed getting body of duckduckgo.com: %v", err)
}
log.Println("Body of duckduckgo.com starts with:")
log.Println(body[0:100])
}