search
LoginSignup
14

More than 5 years have passed since last update.

posted at

updated at

Organization

Scala で PhantomJS を使う

Selenium と PhantomJS ドライバーを入れるだけ。

build.sbt
name := "HogeHoge"

version := "0.1"

scalaVersion := "2.10.3"

libraryDependencies += ("com.github.detro.ghostdriver" % "phantomjsdriver" % "1.1.0").
                        exclude("org.seleniumhq.selenium", "jetty-repacked")

あとは FirefoxDriver と同じように扱える。

main.scala
def main(args: Array[String]) {
    implicit val driver = new PhantomJSDriver()

    driver.get("http://google.com")
    val file = driver.getScreenshotAs(OutputType.FILE)
    Files.copy(Paths.get(file.toURI), Paths.get(file.getName))

    driver.quit()
}

結果

screenshot1875077328556248451.png

ちょうかんたん!

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
What you can do with signing up
14