| 1 |
// Package main ... |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"log" |
| 6 |
"strings" |
| 7 |
|
| 8 |
"github.com/go-rod/rod" |
| 9 |
"github.com/go-rod/rod/lib/input" |
| 10 |
) |
| 11 |
|
| 12 |
// This example demonstrates how to fill out and submit a form. |
| 13 |
func main() { |
| 14 |
page := rod.New().MustConnect().MustPage("https://github.com/search") |
| 15 |
|
| 16 |
page.MustElement(`input[name=q]`).MustWaitVisible().MustInput("chromedp").MustType(input.Enter) |
| 17 |
|
| 18 |
res := page.MustElementR("a", "chromedp").MustParent().MustParent().MustNext().MustText() |
| 19 |
|
| 20 |
log.Printf("got: `%s`", strings.TrimSpace(res)) |
| 21 |
} |