2017-01-24 15:09:23 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
cdp "github.com/knq/chromedp"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
|
|
|
|
// create context
|
|
|
|
ctxt, cancel := context.WithCancel(context.Background())
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
// create chrome instance
|
2017-02-14 08:41:23 +00:00
|
|
|
c, err := cdp.New(ctxt, cdp.WithLog(log.Printf))
|
2017-01-24 15:09:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// run task list
|
|
|
|
err = c.Run(ctxt, click())
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// shutdown chrome
|
|
|
|
err = c.Shutdown(ctxt)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// wait for chrome to finish
|
|
|
|
err = c.Wait()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func click() cdp.Tasks {
|
|
|
|
return cdp.Tasks{
|
|
|
|
cdp.Navigate(`https://golang.org/pkg/time/`),
|
|
|
|
cdp.WaitVisible(`#footer`),
|
2017-02-12 07:08:40 +00:00
|
|
|
cdp.Click(`#pkg-overview`, cdp.NodeVisible),
|
2017-01-24 15:09:23 +00:00
|
|
|
cdp.Sleep(150 * time.Second),
|
|
|
|
}
|
|
|
|
}
|