Skip to content

Instantly share code, notes, and snippets.

@edwin
Created May 18, 2019 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save edwin/49be66615237a506498c72ccff1cb6c9 to your computer and use it in GitHub Desktop.
Save edwin/49be66615237a506498c72ccff1cb6c9 to your computer and use it in GitHub Desktop.
"robot" untuk simpan screenshot web hitung suara kpu (pemilu2019.kpu.go.id) setiap 10 detik
package com.edw.situng;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
*
* @author Muhammad Edwin < edwinkun at gmail dot com >
* 18 May 2019 11:46
*/
public class Main {
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.gecko.driver","E:\\software\\GeckoDriver\\geckodriver.exe");
WebDriver driver = null;
for (int i = 0; i < 10; i++) {
driver = new FirefoxDriver();
driver.manage().window().fullscreen();
driver.get("https://pemilu2019.kpu.go.id/#/ppwp/hitung-suara/");
Thread.sleep(2000);
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("E:\\tmp\\"+new SimpleDateFormat("yyyyMMddHHmmSS").format(new Date()) +".situng.png"));
Thread.sleep(8000);
driver.close();
}
if(driver != null )
driver.quit();
}
}
@edwin
Copy link
Author

edwin commented May 18, 2019

pom-nya ketinggalan

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.edw.situng</groupId>
    <artifactId>Situng Capturer</artifactId>
    <version>1.0</version>

    <dependencies>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <version>2.33.2</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>
    </dependencies>
</project>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment