-
Notifications
You must be signed in to change notification settings - Fork 241
/
main.go
37 lines (31 loc) · 897 Bytes
/
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
// Command submit is a chromedp example demonstrating how to fill out and
// submit a form.
package main
import (
"context"
"log"
"strings"
"github.com/chromedp/chromedp"
)
func main() {
// create context
ctx, cancel := chromedp.NewContext(context.Background(), chromedp.WithDebugf(log.Printf))
defer cancel()
// run task list
var res string
err := chromedp.Run(ctx, submit(`https://github.com/search`, `//input[@name="q"]`, `chromedp`, &res))
if err != nil {
log.Fatal(err)
}
log.Printf("got: `%s`", strings.TrimSpace(res))
}
func submit(urlstr, sel, q string, res *string) chromedp.Tasks {
return chromedp.Tasks{
chromedp.Navigate(urlstr),
chromedp.WaitVisible(sel),
chromedp.SendKeys(sel, q),
chromedp.Submit(sel),
chromedp.WaitVisible(`//*[contains(., 'repository results')]`),
chromedp.Text(`(//*//ul[contains(@class, "repo-list")]/li[1]//p)[1]`, res),
}
}