-
-
Notifications
You must be signed in to change notification settings - Fork 162
/
main.go
48 lines (42 loc) · 1.19 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
//go:build ignore
// +build ignore
package main
import (
"fmt"
"log"
"github.com/playwright-community/playwright-go"
)
func main() {
pw, err := playwright.Run()
if err != nil {
log.Fatal(err)
}
browser, err := pw.Chromium.Launch()
if err != nil {
log.Fatalf("could not launch browser: %v\n", err)
}
page, err := browser.NewPage()
if err != nil {
log.Fatalf("could not create page: %v\n", err)
}
if _, err = page.Goto("https://en.wikipedia.org/wiki/JavaScript"); err != nil {
log.Fatalf("could not goto: %v\n", err)
}
// mw.config.values is the JS object where Wikipedia stores wiki metadata
handle, err := page.EvaluateHandle("mw.config.values", struct{}{})
if err != nil {
log.Fatalf("could not acquire JSHandle: %v\n", err)
}
// mw.config.values.wgPageName is the name of the current page
pageName, err := handle.GetProperty("wgPageName")
if err != nil {
log.Fatalf("could not get Wikipedia page name: %v\n", err)
}
fmt.Printf("Lots of type casting, brought to you by %s\n", pageName)
if err := browser.Close(); err != nil {
log.Fatalf("could not close browser: %v\n", err)
}
if err := pw.Stop(); err != nil {
log.Fatalf("could not stop Playwright: %v\n", err)
}
}