GoogleChrome でリンクをたどるサンプルです。
follow_link_chrome.go
// ---------------------------------------------------------------
//
// follow_link_chrome.go
//
// Sep/23/2018
// ---------------------------------------------------------------
package main
import (
"github.com/sclevine/agouti"
"fmt"
"os"
"log"
)
// ---------------------------------------------------------------
func main() {
fmt.Fprintf (os.Stderr,"*** 開始 ***\n")
driver := agouti.ChromeDriver()
driver.Start()
// defer driver.Stop()
page, _ := driver.NewPage()
url := "https://ekzemplaro.org"
page.Navigate(url)
log.Printf(page.Title())
page.Screenshot("Screenshot01.png")
tag := page.FindByID("ekzemplaro")
tag.Click()
log.Printf(page.Title())
page.Screenshot("Screenshot02.png")
tag = page.FindByLink("English")
tag.Click()
log.Printf(page.Title())
page.Screenshot("Screenshot03.png")
fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}
// ---------------------------------------------------------------
Makefile
follow_link_chrome: follow_link_chrome.go
go build follow_link_chrome.go
clean:
rm -f follow_link_chrome
コンパイル
$ make
go build follow_link_chrome.go
実行方法
export PATH=/opt/chromedriver:$PATH
./follow_link_chrome