{"id":485,"date":"2025-02-18T16:55:05","date_gmt":"2025-02-18T07:55:05","guid":{"rendered":"https:\/\/www.flumen-jp.com\/wordpress\/?p=485"},"modified":"2025-07-25T17:32:32","modified_gmt":"2025-07-25T08:32:32","slug":"seleniumvba2","status":"publish","type":"post","link":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2025\/02\/18\/seleniumvba2\/","title":{"rendered":"SeleniumVBA(2)"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>\u3000<a href=\"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/2024\/04\/30\/seleniumvba\/\" target=\"_blank\" rel=\"noreferrer noopener\">\u4ee5\u524d\u7d39\u4ecb\u3057\u305f<\/a> SeleniumVBA \u3092\u4f7f\u3063\u3066\u6c17\u8c61\u5e81\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u304b\u3089 10 \u5206\u96e8\u91cf\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u3092\u884c\u3063\u305f\u3002<br>\u3000\u4f7f\u7528\u983b\u5ea6\u304c\u591a\u3044\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3068\u8003\u3048\u3089\u308c\u308b\u306e\u3067\u304a\u62ab\u9732\u76ee\u3059\u308b\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>Const URL_PREFIX = &quot;https:\/\/www.data.jma.go.jp\/obd\/stats\/etrn\/view\/10min_s1.php?prec_no=[pref]&block_no=[block]&quot;\nConst DRIVER_PATH = &quot;C:\\[directory]\\chromedriver.exe&quot;\n\nPrivate Sub Get_Rainfall_data()\n\n    Dim data(1 to 144) As Double\n    Dim caps As Object\n\n    dt = #1\/1\/2015#: dt_exit = #1\/1\/2025#\n\n    Open ThisWorkbook.Path & &quot;\\rainfall.csv&quot; For Output As #1\n\n    With New SeleniumVBA.WebDriver\n\n        .StartChrome DRIVER_PATH\n        Set caps = .CreateCapabilities\n        caps.RunInvisible\n\n        .OpenBrowser caps\n\n        Do\n\n            url = URL_PREFIX & &quot;&year=&quot; & Year(dt)\n            url = url & &quot;&month=&quot; & Month(dt)\n            url = url & &quot;&day=&quot; & Day(dt) & &quot;&view=h1&quot;\n\n            .NavigateTo url\n            .Wait 200\n\n            With .FindElementByID(&quot;tablefix1&quot;)\n                row_num = 1\n                idx = 0\n                For Each row In .FindElementsByTagName(&quot;tr&quot;)\n                    If row_num &gt; 2 Then\n                        txt = row.FindElementsByTagName(&quot;td&quot;). _\n                                   Item(4).GetInnerHTML\n                        idx = idx + 1\n                        If IsNumeric(txt) Then\n                            data(idx) = Val(txt)\n                        Else\n                            data(idx) = 0\n                        End If\n                    End If\n                    row_num = row_num + 1\n                Next\n            End With\n\n            dt_pr = DateAdd(&quot;n&quot;, 10, dt)\n            For idx = 1 To 144\n                buf = Format(dt_pr, &quot;yyyy\/mm\/dd hh:nn&quot;) & &quot;,&quot; & _\n                      Format(data(idx), &quot;0.0&quot;)\n                Print #1, buf\n                dt_pr = DateAdd(&quot;n&quot;, 10, dt_pr)\n            Next\n\n            dt = dt + 1\n            If dt = dt_exit Then Exit Do\n\n        Loop\n\n        .CloseBrowser\n        .Shutdown\n\n    End With\n\n    Close #1\n    Set caps = Nothing\n\nEnd Sub<\/code><\/pre><\/div>\n\n\n\n<p>\u3000\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u969b\u306b\u4f7f\u3046\u5834\u5408\u306f\u30011 \u884c\u76ee\u306e URL_PREFIX \u306f\u6c17\u8c61\u5e81\u306e\u300c<a href=\"https:\/\/www.data.jma.go.jp\/obd\/stats\/etrn\/index.php\" target=\"_blank\" rel=\"noreferrer noopener\">\u904e\u53bb\u306e\u6c17\u8c61\u30c7\u30fc\u30bf\u691c\u7d22<\/a>\u300d\u3067\u6240\u671b\u306e\u89b3\u6e2c\u6240\u30fb\u65e5\u6642\u306e\u300c10 \u5206\u3054\u3068\u306e\u5024\u300d\u3092\u8868\u793a\u3057\u3066\u3001\u9077\u79fb\u753b\u9762\u306e URL \u304b\u3089 [pref] \u3068 [block] \u3092\u8aad\u53d6\u3063\u3066\u66f8\u304d\u63db\u3048\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\u307e\u305f\u30012 \u884c\u76ee\u306e DRIVER_PATH \u306e [directory] \u306f chromedriver.exe \u304c\u4fdd\u5b58\u3055\u308c\u3066\u3044\u308b\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306b\u66f8\u304d\u63db\u3048\u308b\u3002\u3055\u3089\u306b\u30018 \u884c\u76ee\u306e dt \u306f\u958b\u59cb\u65e5\u3001dt_exit \u306f\u672b\u5c3e\u306e\u7fcc\u65e5\u3092\u6307\u5b9a\u3059\u308b\u3002<br>\u300035 \u884c\u76ee\u306e Item(4) \u306f\u8868\u306e 4 \u5217\u76ee\u306b\u96e8\u91cf\u304c\u8868\u793a\u3055\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u6307\u3059\u3002\u89b3\u6e2c\u6240\u306b\u3088\u3063\u3066\u8868\u793a\u9805\u76ee\u304c\u7570\u306a\u308b\u306e\u3067\u76f8\u9055\u3059\u308b\u5834\u5408\u306f\u5909\u66f4\u3092\u52a0\u3048\u308b\u3002 <br>\u3000\u4ee5\u4e0a\u306e\u7de8\u96c6\u3068 SeleniumVBA \u306e\u53c2\u7167\u8a2d\u5b9a\u3092\u884c\u3063\u3066\u3001Get_Rainfall_data \u3092\u30b3\u30fc\u30eb\u3059\u308b\u3068\u6307\u5b9a\u3057\u305f\u671f\u9593\u306e 10 \u5206\u96e8\u91cf\u304c rainfall.csv \u306b\u51fa\u529b\u3055\u308c\u308b\u3002<br>\u3000\u4eca\u56de\u300110 \u5e74\u5206\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3059\u308b\u306e\u306b\u8981\u3057\u305f\u6642\u9593\u306f\u8457\u8005\u306e\u74b0\u5883\u3067\u7d04 4 \u6642\u9593\u3067\u3042\u3063\u305f\uff08\u5bdd\u3066\u3044\u308b\u9593\u306b\u51e6\u7406\uff09\u3002<br>\u3000\u306a\u304a\u3001\u30ef\u30fc\u30af\u30d6\u30c3\u30af\u306e\u5206\u5272\u306b\u3088\u308b\u4e26\u5217\u51e6\u7406\u3092\u8a66\u307f\u305f\u304c\u3001Chrome \u306e\u4ed5\u69d8\u30fbVBA \u306e\u4ed5\u69d8\u306e\u4f55\u308c\u306b\u62e0\u308b\u3082\u306e\u304b\u306f\u5206\u304b\u3089\u306a\u3044\u304c\u3001\u672a\u9042\u3067\u3042\u3063\u305f\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3000\u4ee5\u524d\u7d39\u4ecb\u3057\u305f SeleniumVBA \u3092\u4f7f\u3063\u3066\u6c17\u8c61\u5e81\u306e\u30a6\u30a7\u30d6\u30b5\u30a4\u30c8\u304b\u3089 10 \u5206\u96e8\u91cf\u30c7\u30fc\u30bf\u306e\u53d6\u5f97\u3092\u884c\u3063\u305f\u3002\u3000\u4f7f\u7528\u983b\u5ea6\u304c\u591a\u3044\u30e6\u30fc\u30b9\u30b1\u30fc\u30b9\u3068\u8003\u3048\u3089\u308c\u308b\u306e\u3067\u304a\u62ab\u9732\u76ee\u3059\u308b\u3002 \u3000\u3053\u306e\u30b3\u30fc\u30c9\u3092\u5b9f\u969b\u306b\u4f7f\u3046\u5834\u5408\u306f\u30011 \u884c\u76ee\u306e URL_ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[30,31],"class_list":["post-485","post","type-post","status-publish","format-standard","hentry","category-it","tag-seleniumvba","tag-vba"],"_links":{"self":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/485","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=485"}],"version-history":[{"count":9,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/485\/revisions"}],"predecessor-version":[{"id":616,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/485\/revisions\/616"}],"wp:attachment":[{"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=485"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=485"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.flumen-jp.com\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=485"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}