-
Notifications
You must be signed in to change notification settings - Fork 4
/
leetcode.go
61 lines (51 loc) · 1.39 KB
/
leetcode.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
// Command simple is a chromedp example demonstrating how to do a simple google
// search.
package main
import (
"context"
"log"
"github.com/chromedp/chromedp"
)
func main() {
var err error
// create context
ctxt, cancel := context.WithCancel(context.Background())
defer cancel()
// create chrome instance
c, err := chromedp.New(ctxt, chromedp.WithLog(log.Printf))
if err != nil {
log.Fatal(err)
}
// run task list
var function string
err = c.Run(ctxt, getFunction(&function))
if err != nil {
log.Println("Run error")
log.Fatal(err)
}
// shutdown chrome
err = c.Shutdown(ctxt)
if err != nil {
log.Println("Shutdown error")
log.Fatal(err)
}
// wait for chrome to finish
err = c.Wait()
if err != nil {
log.Println("Wait error")
log.Fatal(err)
}
log.Println(function)
}
func getFunction(function *string) chromedp.Tasks {
textarea := `//textarea`
btn := `#question-detail-app > div > div:nth-child(3) > div > div > div.row.control-btn-bar > div > div > div > div > span.Select-arrow-zone`
goSel := `#react-select-2--option-9`
return chromedp.Tasks{
// chromedp.Navigate(`https://leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/description/`),
chromedp.Navigate(`https://leetcode.com/problems/k-th-symbol-in-grammar/description/`),
chromedp.Click(btn, chromedp.ByID),
chromedp.Click(goSel, chromedp.ByID),
chromedp.Text(textarea, function),
}
}