Help us understand the problem. What is going on with this article?

Selenium と google-chrome でページを取得して保存 (Golang)

More than 1 year has passed since last update.
chrome_save.go
// ---------------------------------------------------------------
//
//  chrome_save.go
//
//                  Sep/26/2018
// ---------------------------------------------------------------
package main

import (
    "github.com/sclevine/agouti"
    "fmt"
    "os"
    "log"
    "io/ioutil"
        "time"
)

// ---------------------------------------------------------------
func main() {
    fmt.Fprintf (os.Stderr,"*** 開始 ***\n")

    url := "https://ekzemplaro.org/storytelling"
    driver := agouti.ChromeDriver()

    err := driver.Start() 
    if err != nil {
        log.Printf("Failed to start driver: %v", err)
    }

    page, err := driver.NewPage(agouti.Browser("chrome"))
    if err != nil {
        log.Printf("Failed to open page: %v", err)
    }

    err = page.Navigate(url)
    if err != nil {
        log.Printf("Failed to navigate: %v", err)
    }

    fmt.Printf(page.Title())
    fmt.Printf("\n")
    fmt.Printf(page.URL())
    fmt.Printf("\n")

    page.Screenshot("tmp001.jpg")

        time.Sleep(100 * time.Millisecond)

    html, err := page.HTML()
    fmt.Printf (html)
    fmt.Printf("\n")

    out_filename := "tmp001.html"
    ioutil.WriteFile (out_filename,[]byte(html),0666)

        defer driver.Stop()

    fmt.Fprintf (os.Stderr,"*** 終了 ***\n")
}

// ---------------------------------------------------------------
Makefile
chrome_save: chrome_save.go
    go build chrome_save.go
clean:
    rm -f chrome_save

コンパイル

$ make
go build chrome_save.go

実行方法

export PATH=/opt/chromedriver:$PATH
./chrome_save
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away