1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Selenium でリンクをたどる (Golang)

Posted at

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
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?