FROM golang:1.10.2-alpine\n\nRUN apk add --no-cache chromium chromium-chromedriver git bash && \n go get -u github.com\/golang\/dep\/cmd\/dep && \n go get -u github.com\/golang\/lint\/golint\n\nWORKDIR \/go\/src\/chromium-test\nCOPY . \/go\/src\/chromium-test<\/code><\/pre>\ndocker-compose.yml\u306e\u8a2d\u5b9a<\/h2>\n
\u3044\u308d\u3044\u308d\u3068\u697d\u3059\u308b\u305f\u3081\u3001docker-compose\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002
\nDockerfile\u306e\u8a2d\u5b9a\u3068Go\u306e\u30d3\u30eb\u30c9&\u5b9f\u884c\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u8a2d\u5b9a\u3092\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
docker-compose.yml<\/code><\/p>\nversion: '3'\nservices:\n go:\n command: .\/run.sh\n build:\n context: .\/\n dockerfile: .\/Dockerfile\n volumes:\n - .:\/go\/src\/chromium-test<\/code><\/pre>\nrun.sh<\/code>\u306f\u3001Go\u306e\u30d3\u30eb\u30c9&\u5b9f\u884c\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u3059\u3002
\ndep\u3067\u4f9d\u5b58\u95a2\u4fc2\u30e2\u30b8\u30e5\u30fc\u30eb\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n#!\/bin\/sh\n\ndep ensure\nCGO_ENABLED=0 GOOS=linux go build -v -a -installsuffix cgo -o .\/main .\/main.go\n.\/main<\/code><\/pre>\nGo\u3067\u4f7f\u7528\u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u8a2d\u5b9a<\/h2>\n
Gopkg.toml<\/code>\u306f\u3001dep\u30b3\u30de\u30f3\u30c9\u3067\u8aad\u307f\u8fbc\u307e\u308c\u308b\u4f9d\u5b58\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3067\u3059\u3002
\nHeadless Chrome\u3092Go\u304b\u3089\u4f7f\u7528\u3059\u308b\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb(agouti)\u3068.env\u3092\u8aad\u307f\u8fbc\u3080\u305f\u3081\u306e\u30e2\u30b8\u30e5\u30fc\u30eb(godotenv)\u3092\u8a18\u8ff0\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n[prune]\n go-tests = true\n unused-packages = true\n\n[[constraint]]\n name = \"github.com\/sclevine\/agouti\"\n version = \"3.0.0\"\n\n[[constraint]]\n name = \"github.com\/joho\/godotenv\"\n version = \"1.2.0\"<\/code><\/pre>\n\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u30b9\u30af\u30ea\u30d7\u30c8<\/h2>\n
\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u3001\u30b3\u30f3\u30bd\u30fc\u30eb\u4e0a\u306e\u4ee5\u4e0b\u306e\u90e8\u5206\u3092\u53d6\u5f97\u3057\u307e\u3059(\u6570\u5024\u306f\u6539\u5909\u3057\u3066\u3044\u307e\u3059)\u3002<\/p>\n
<\/p>\n
\u30a2\u30ab\u30a6\u30f3\u30c8\u60c5\u5831\u306a\u3069\u306f.env<\/code>\u30d5\u30a1\u30a4\u30eb\u306b\u8a18\u8ff0\u3057\u307e\u3059\u3002
\nGit\u7ba1\u7406\u306b\u542b\u3081\u306a\u3044\u3088\u3046\u306b\u6ce8\u610f\u3057\u307e\u3059\u3002<\/p>\nACCOUNT_ID=xxxxxxxxxxxxxxxx\nUSER_NAME=xxxxxxxxxxxxxxxx\nPASSWORD=xxxxxxxxxxxxxxx\nYEAR=2018\nMONTH=6<\/code><\/pre>\n\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n
main.go<\/code><\/p>\npackage main\n\nimport (\n \"github.com\/sclevine\/agouti\"\n \"github.com\/joho\/godotenv\"\n \"log\"\n \"fmt\"\n \"time\"\n \"strconv\"\n \"strings\"\n \"os\"\n)\n\nfunc main() {\n err := godotenv.Load()\n if err != nil {\n log.Fatal(\"Error loading .env file\")\n }\n\n accountID := os.Getenv(\"ACCOUNT_ID\")\n userName := os.Getenv(\"USER_NAME\")\n password := os.Getenv(\"PASSWORD\")\n year := os.Getenv(\"YEAR\")\n month := os.Getenv(\"MONTH\")\n\n billingURL := fmt.Sprintf(\"https:\/\/console.aws.amazon.com\/billing\/home?region=ap-northeast-1#\/bills?year=%s&month=%s\", year, month)\n\n log.Println(\"--- Create driver\")\n driver := agouti.ChromeDriver(\n agouti.ChromeOptions(\"args\", []string{\n \"--headless\",\n \"--disable-gpu\",\n \"--window-size=1280,800\",\n \"--disable-application-cache\",\n \"--disable-infobars\",\n \"--no-sandbox\",\n \"--hide-scrollbars\",\n \"--enable-logging\",\n \"--log-level=0\",\n \"--v=99\",\n \"--single-process\",\n \"--homedir=\/tmp\",\n \"--allow-insecure-localhost\",\n }),\n agouti.Debug,\n )\n if err := driver.Start(); err != nil {\n log.Fatal()\n }\n defer driver.Stop()\n\n page, err := driver.NewPage()\n if err != nil {\n log.Fatal(err)\n }\n\n log.Println(\"--- Access login page\")\n err = page.Navigate(fmt.Sprintf(\"https:\/\/%s.signin.aws.amazon.com\/console\", accountID))\n if err != nil {\n log.Fatalf(\"Failed to navigate: %v\", err)\n }\n html, err := page.HTML()\n if err != nil {\n log.Fatalf(\"Failed to login:%v\", err)\n }\n\n identityElm := page.FindByID(\"username\")\n passwordElm := page.FindByID(\"password\")\n identityElm.Fill(userName)\n passwordElm.Fill(password)\n log.Println(\"--- Start login\")\n if err := page.FindByID(\"signin_button\").Click(); err != nil {\n log.Fatalf(\"Failed to login:%v\", err)\n }\n time.Sleep(3 * time.Second)\n \/\/page.Screenshot(\"Screen2.png\")\n\n\n log.Println(\"--- Access billing page\")\n page.Navigate(billingURL)\n time.Sleep(10 * time.Second)\n\n billFxAmount, err := page.Find(\"#totalAmount #billFxAmount\").Text()\n if err != nil {\n log.Fatal(err)\n }\n\n billStr := strings.Replace(billFxAmount, \" JPY\", \"\", 1)\n billStr = strings.Replace(billStr, \",\", \"\", -1)\n billF, err := strconv.ParseFloat(billStr, 64)\n if err != nil {\n log.Fatal(err)\n }\n\n println(int(billF))\n}<\/code><\/pre>\nHTML\u3092\u89e3\u6790\u3057\u3066\u30c7\u30fc\u30bf\u53d6\u5f97\u3092\u884c\u3063\u3066\u3044\u308b\u305f\u3081\u3001\u306a\u306b\u304b\u3057\u3089\u66f4\u65b0\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u3046\u307e\u304f\u52d5\u4f5c\u3057\u306a\u3044\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u3002
\n\u4e0a\u624b\u304f\u52d5\u4f5c\u3057\u306a\u3044\u5834\u5408\u306f\u3001page.Screenshot(\"Screen.png\")<\/code>\u306a\u3069\u3092\u4f7f\u7528\u3057\u3066\u3001
\n\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8\u3092\u78ba\u8a8d\u3057\u306a\u304c\u3089\u30c7\u30d0\u30c3\u30b0\u3059\u308b\u3068\u826f\u3044\u3067\u3059\u3002<\/p>\n\u4ee5\u4e0b\u306e\u30b3\u30de\u30f3\u30c9\u3067\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5b9f\u884c\u3057\u307e\u3059\u3002<\/p>\n
$ docker-compose run go .\/run.sh<\/code><\/pre>\n\u51e6\u7406\u304c\u3046\u307e\u304f\u3044\u3051\u3070\u3001\u6599\u91d1\u304c\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n
\u307e\u3068\u3081<\/h2>\n
AWS\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3066\u65e5\u672c\u5186\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002
\n\u3053\u306e\u65b9\u6cd5\u306f\u304b\u306a\u308a\u7121\u7406\u3084\u308a\u306a\u306e\u3067\u3001API\u304c\u5bfe\u5fdc\u3057\u305f\u3089\u5373\u5ec3\u6b62\u306b\u3057\u305f\u3044\u3067\u3059\u306d\u3002
\n\u305d\u308c\u307e\u3067\u306f\u6ce8\u610f\u3057\u3066\u904b\u7528\u3057\u3066\u884c\u3053\u3046\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
<\/body><\/html><\/p>\n","protected":false},"excerpt":{"rendered":"
\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u5185\u5c71\u3067\u3059\u3002\u6700\u8fd1\u306f\u6691\u3059\u304e\u3066\u3001\u305a\u3063\u3068\u6c57\u3092\u304b\u3044\u3066\u307e\u3059\u3002 \u4eca\u56de\u306f\u3001Go\u8a00\u8a9e\u3068Headless Chrome\u3092\u4f7f\u3063\u3066\u3001 AWS\u30b3\u30f3\u30bd\u30fc\u30eb\u3092\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3057\u3001 AWS\u6708\u984d\u5229\u7528\u6599\u91d1\u3092\u65e5\u672c\u5186\u3067\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u3092\u3054\u7d39\u4ecb\u3057\u307e\u3059\u3002 \u76ee\u6b21 \u53d6\u5f97\u65b9\u6cd5\u306e\u691c\u8a0e \u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u7528\u306e\u30a2\u30ab\u30a6\u30f3\u30c8\u3092\u8a2d\u5b9a \u4f7f\u7528\u3059\u308b\u30c4\u30fc\u30eb Dockerfile\u306e\u8a2d\u5b9a docker-compose.yml\u306e\u8a2d\u5b9a Go\u3067\u4f7f\u7528\u3059\u308b\u30e2\u30b8\u30e5\u30fc\u30eb\u306e\u8a2d\u5b9a \u30b9\u30af […]<\/p>\n","protected":false},"author":5,"featured_media":684,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[73,128],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/467"}],"collection":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":1,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":3303,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/posts\/467\/revisions\/3303"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}