| 1 |
// Package main ... |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"log" |
| 6 |
"time" |
| 7 |
|
| 8 |
"github.com/go-rod/rod" |
| 9 |
) |
| 10 |
|
| 11 |
// On awesome-go page, finding the specified section sect, |
| 12 |
// and retrieving the associated projects from the page. |
| 13 |
func main() { |
| 14 |
page := rod.New().MustConnect().Timeout(time.Second * 15).MustPage("https://github.com/avelino/awesome-go") |
| 15 |
|
| 16 |
section := page.MustElementR("p", "Selenium and browser control tools").MustNext() |
| 17 |
|
| 18 |
// query children elements of an element |
| 19 |
projects := section.MustElements("li") |
| 20 |
|
| 21 |
for _, project := range projects { |
| 22 |
link := project.MustElement("a") |
| 23 |
log.Printf( |
| 24 |
"project %s (%s): '%s'", |
| 25 |
link.MustText(), |
| 26 |
link.MustProperty("href"), |
| 27 |
project.MustText(), |
| 28 |
) |
| 29 |
} |
| 30 |
} |