{"id":2354,"date":"2022-05-04T18:16:32","date_gmt":"2022-05-04T09:16:32","guid":{"rendered":"http:\/\/oreoreki.gotdns.ch\/?p=2354"},"modified":"2022-07-04T14:28:34","modified_gmt":"2022-07-04T05:28:34","slug":"post-2354","status":"publish","type":"post","link":"http:\/\/oreoreki.gotdns.ch\/?p=2354","title":{"rendered":"VBA\u3067Edge\u64cd\u4f5c\u3092\u81ea\u52d5\u5316\u3057\u3066\u307f\u305f"},"content":{"rendered":"<p>VBA\u3067Edge\u64cd\u4f5c\u3092\u81ea\u52d5\u5316\u3057\u3066\u307f\u305f\u3002<\/p>\r\n <span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe loading=\"lazy\" class=\"youtube-player\" width=\"750\" height=\"422\" src=\"https:\/\/www.youtube.com\/embed\/6kbFZQSLyVQ?version=3&#038;rel=1&#038;showsearch=0&#038;showinfo=1&#038;iv_load_policy=1&#038;fs=1&#038;hl=ja&#038;autohide=2&#038;wmode=transparent\" allowfullscreen=\"true\" style=\"border:0;\" sandbox=\"allow-scripts allow-same-origin allow-popups allow-presentation allow-popups-to-escape-sandbox\"><\/iframe><\/span> \r\n\r\n<span class=\"bold-red\">.NET Framework\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3001\u5b9f\u884c\u6642\u306b\u30aa\u30fc\u30c8\u30e1\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3059\u3002 \u30aa\u30fc\u30c8\u30e1\u30fc\u30b7\u30e7\u30f3\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u5834\u5408\u3001.NET Framework 3.5\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/span><\/p>\r\n\r\n<p><span class=\"bold-red\">\u52d5\u753b\u3067\u306fEdge\u3067\u306e\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u304c\u8a2d\u5b9a\u51fa\u6765\u306a\u3044\u3068\u8a00\u3063\u3066\u307e\u3059\u304c\u3001 Edge\u3067\u306e\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u5909\u66f4\u65b9\u6cd5\u304c\u5224\u660e\u3057\u307e\u3057\u305f\uff01<\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>    '\u30d6\u30e9\u30a6\u30b6\u3092\u8d77\u52d5\r\n    Dim driver As New Selenium.WebDriver\r\n    Set driver = CreateObject(\"Selenium.webDriver\")\r\n\r\n    'Edge\u306b\u8d77\u52d5\u30aa\u30d7\u30b7\u30e7\u30f3\u3092json\u3067\u6e21\u3059\r\n    driver.SetCapability \"ms:edgeOptions\", \"{\"\"args\"\": [\"\"user-data-dir=\" & Replace(fso.BuildPath(CurrentDirectory, \"edge_vba1\"), \"\\\", \"\\\\\") & \"\"\"\" & _\r\n    \",\"\"disable-blink-features=AutomationControlled\"\"\" & _\r\n    \"] }\"\r\n\r\n    driver.Start \"edge\"\r\n<\/code><\/pre>\r\n<\/div>\r\n\r\n<div class=\"hcb_wrap\">VBA\u3067\u4f5c\u3063\u305f\u307f\u305f\u3002\r\n<pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>Option Explicit\r\n#If Win64 Then\r\n    ' Excel \u304c64\u30d3\u30c3\u30c8\u7248\u306e\u5834\u5408\u306e\u95a2\u6570\u5b9a\u7fa9\u3067\u3059\u3002\r\n    Private Declare PtrSafe Function MessageBoxTimeoutA Lib \"User32.dll\" _\r\n        (ByVal hWnd As LongPtr, _\r\n        ByVal lpText As String, _\r\n        ByVal lpCaption As String, _\r\n        ByVal uType As VbMsgBoxStyle, _\r\n        ByVal wLanguageID As Long, _\r\n        ByVal dwMilliseconds As Long) As Long\r\n#Else\r\n    ' Excel \u304c32\u30d3\u30c3\u30c8\u7248\u306e\u5834\u5408\u306e\u95a2\u6570\u5b9a\u7fa9\u3067\u3059\u3002\r\n    Private Declare Function MessageBoxTimeoutA Lib \"User32.dll\" _\r\n        (ByVal hWnd As Long, _\r\n        ByVal lpText As String, _\r\n        ByVal lpCaption As String, _\r\n        ByVal uType As VbMsgBoxStyle, _\r\n        ByVal wLanguageID As Long, _\r\n        ByVal dwMilliseconds As Long) As Long\r\n#End If\r\n\r\nSub Macro()\r\n    Dim driver, o_elem, fso, file, str_user, str_pass, CurrentDirectory, myBy, bFlag, num_trend_word, i\r\n    \r\n    '\u30d1\u30b9\u30ef\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3080\r\n    Set fso = CreateObject(\"Scripting.FileSystemObject\")\r\n    CurrentDirectory = ActiveWorkbook.Path\r\n    Set file = fso.OpenTextFile(fso.BuildPath(CurrentDirectory, \"pass1.txt\"), 1)\r\n    str_user = file.ReadLine\r\n    str_pass = file.ReadLine\r\n    file.Close\r\n    Set file = Nothing\r\n  \r\n    'Edge\u30d6\u30e9\u30a6\u30b6\u3092\u8d77\u52d5\r\n    Set driver = CreateObject(\"Selenium.webDriver\")\r\n    \r\n    'Edge\u3060\u3068AddArgument\u304c\u52d5\u304b\u306a\u3044\u3002python\u3060\u3068\u52d5\u304f\r\n    driver.AddArgument \"user-data-dir=\" &amp; fso.BuildPath(CurrentDirectory, \"edge_vba\")\r\n    driver.Start \"Edge\"\r\n    driver.Get \"https:\/\/websearch.rakuten.co.jp\/\"\r\n\r\n    Set o_elem = driver.FindElementsByPartialLinkText(\"\u30ed\u30b0\u30a4\u30f3\")\r\n    If o_elem.Count &gt; 0 Then\r\n        '\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044  \u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\r\n        driver.ExecuteScript \"arguments[0].click();\", o_elem.Item(1)\r\n        '\u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u30a8\u30ea\u30a2\u304c\u51fa\u73fe\u3059\u308b\u307e\u3067\u5f85\u3064\r\n        Call WaitElementbyCss(driver, \"#loginInner_p\")\r\n        \r\n        driver.FindElementByCss(\"#loginInner_p\").SendKeys str_pass\r\n        driver.FindElementByCss(\"#loginInner_u\").SendKeys str_user\r\n        driver.FindElementByCss(\"input.loginButton\").Click\r\n    End If\r\n    \r\n    '\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u914d\u5217\u306b\u683c\u7d0d\r\n    Call WaitElementbyCss(driver, \"div.TrendWord-module__trendWordWrap__19AOz input\")\r\n    Set o_elem = driver.FindElementsByCss(\"div.TrendWord-module__trendWordWrap__19AOz input\")\r\n    num_trend_word = o_elem.Count\r\n    Dim str_trend_word(5)\r\n    For i = 1 To num_trend_word\r\n        str_trend_word(i - 1) = o_elem.Item(i).Value\r\n    Next\r\n    \r\n    '\u914d\u5217\u306b\u683c\u7d0d\u3055\u308c\u305f\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u691c\u7d22\u3059\u308b\r\n    For i = 0 To num_trend_word\r\n        '\u691c\u7d22\u7a93\u306b\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3059\u308b\r\n        Set o_elem = driver.FindElementsByCss(\"#search-input,#srchformtxt_qt\")\r\n        o_elem.Item(1).Clear\r\n        o_elem.Item(1).SendKeys str_trend_word(i)\r\n        '\u691c\u7d22\u30dc\u30bf\u30f3\u3092\u62bc\u3059\r\n        Set o_elem = driver.FindElementsByCss(\"#search-submit,#searchBtn\")\r\n        o_elem.Item(1).Click\r\n        MessageBoxTimeoutA 0&amp;, \"1\u79d2\u5f8c\u3001\u81ea\u52d5\u306b\u9589\u3058\u307e\u3059\", \"\u6642\u9593\u5f85\u3061\u3067\u3059\", 1, 65536, 1 * 1000\r\n    Next\r\n    \r\n    'IE\u3092\u9589\u3058\u308b\r\n    driver.Quit\r\n    Set driver = Nothing\r\nEnd Sub\r\n\r\nSub WaitElementbyCss(driver, css)\r\n    Dim bFlag, myBy\r\n        bFlag = False\r\n        Set myBy = New By\r\n        Do\r\n            bFlag = driver.IsElementPresent(myBy.css(css))\r\n            driver.Wait 1000\r\n        Loop Until bFlag = True\r\nEnd Sub<\/code><\/pre>\r\n<\/div>\r\n\r\n<h2><\/h2>\r\n<div class=\"hcb_wrap\">DOS\u30d0\u30c3\u30c1\u30fbVBScript\u3067\u4f5c\u3063\u305f\u307f\u305f\u3002\r\n<pre class=\"prism line-numbers lang-ts\" data-lang=\"TypeScript\"><code>&lt;!-- :\r\n@%windir%\\System32\\cscript.exe \/\/nologo \"%~f0?.wsf\"\r\n@exit \/b %errorlevel%\r\n--&gt;\r\n&lt;job&gt;\r\n&lt;script language=\"VBScript\"&gt;\r\n\tDim driver, o_elem, fso, file, str_user, str_pass, CurrentDirectory, myBy, bFlag, num_trend_word, i\r\n\r\n\t'\u30d1\u30b9\u30ef\u30fc\u30c9\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u3080\r\n\tSet fso = CreateObject(\"Scripting.FileSystemObject\")\r\n\tCurrentDirectory = fso.getParentFolderName(WScript.ScriptFullName)\r\n\tSet file = fso.OpenTextFile(fso.BuildPath(CurrentDirectory, \"pass1.txt\"), 1)\r\n\tstr_user = file.ReadLine\r\n\tstr_pass = file.ReadLine\r\n\tfile.Close\r\n\tSet file = Nothing\r\n\r\n\t'Edge\u30d6\u30e9\u30a6\u30b6\u3092\u8d77\u52d5\r\n\tSet driver = WScript.CreateObject(\"Selenium.webDriver\")\r\n\tSet myBy = WScript.CreateObject(\"selenium.By\")\r\n\r\n\t'Edge\u3060\u3068AddArgument\u304c\u52d5\u304b\u306a\u3044\u3002python\u3060\u3068\u52d5\u304f\r\n\tdriver.AddArgument \"user-data-dir=\" &amp; fso.BuildPath(CurrentDirectory, \"edge_vba\")\r\n\tdriver.Start \"Edge\"\r\n\tdriver.Get \"https:\/\/websearch.rakuten.co.jp\/\"\r\n\r\n\tSet o_elem = driver.FindElementsByPartialLinkText(\"\u30ed\u30b0\u30a4\u30f3\")\r\n\tIf o_elem.Count &gt; 0 Then\r\n\t\t'\u30ed\u30b0\u30a4\u30f3\u3057\u3066\u3044\u306a\u3044  \u30ea\u30f3\u30af\u3092\u30af\u30ea\u30c3\u30af\r\n\t\tdriver.ExecuteScript \"arguments[0].click();\", o_elem.Item(1)\r\n\t\t'\u30d1\u30b9\u30ef\u30fc\u30c9\u5165\u529b\u30a8\u30ea\u30a2\u304c\u51fa\u73fe\u3059\u308b\u307e\u3067\u5f85\u3064\r\n\t\tCall WaitElementbyCss(driver, \"#loginInner_p\")\r\n\r\n\t\tdriver.FindElementByCss(\"#loginInner_p\").SendKeys str_pass\r\n\t\tdriver.FindElementByCss(\"#loginInner_u\").SendKeys str_user\r\n\t\tdriver.FindElementByCss(\"input.loginButton\").Click\r\n\tEnd If\r\n\r\n\t'\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u914d\u5217\u306b\u683c\u7d0d\r\n\tCall WaitElementbyCss(driver, \"div.TrendWord-module__trendWordWrap__19AOz input\")\r\n\tSet o_elem = driver.FindElementsByCss(\"div.TrendWord-module__trendWordWrap__19AOz input\")\r\n\tnum_trend_word = o_elem.Count\r\n\tDim str_trend_word(5)\r\n\tFor i = 1 To num_trend_word\r\n\t\tstr_trend_word(i - 1) = o_elem.Item(i).Value\r\n\tNext\r\n\r\n\t'\u914d\u5217\u306b\u683c\u7d0d\u3055\u308c\u305f\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u691c\u7d22\u3059\u308b\r\n\tFor i = 0 To num_trend_word\r\n\t\t'\u691c\u7d22\u7a93\u306b\u30c8\u30ec\u30f3\u30c9\u30ef\u30fc\u30c9\u3092\u5165\u529b\u3059\u308b\r\n\t\tSet o_elem = driver.FindElementsByCss(\"#search-input,#srchformtxt_qt\")\r\n\t\to_elem.Item(1).Clear\r\n\t\to_elem.Item(1).SendKeys str_trend_word(i)\r\n\t\t'\u691c\u7d22\u30dc\u30bf\u30f3\u3092\u62bc\u3059\r\n\t\tSet o_elem = driver.FindElementsByCss(\"#search-submit,#searchBtn\")\r\n\t\to_elem.Item(1).Click\r\n\t\tWScript.CreateObject(\"WScript.Shell\").popup \"1\u79d2\u5f8c\u3001\u81ea\u52d5\u306b\u9589\u3058\u307e\u3059\",1, \"\u6642\u9593\u5f85\u3061\u3067\u3059\", 1\r\n\tNext\r\n\r\n\t'IE\u3092\u9589\u3058\u308b\r\n\tdriver.Quit\r\n\tSet driver = Nothing\r\n\r\n\tSub WaitElementbyCss(driver, css)\r\n\t    Dim bFlag, myBy\r\n\t        bFlag = False\r\n\t        Set myBy = WScript.CreateObject(\"Selenium.By\")\r\n\t        Do\r\n\t            bFlag = driver.IsElementPresent(myBy.css(css))\r\n\t            driver.Wait 1000\r\n\t        Loop Until bFlag = True\r\n\tEnd Sub\r\n&lt;\/script&gt;\r\n&lt;\/job&gt;<\/code><\/pre>\r\n<\/div>\r\n","protected":false},"excerpt":{"rendered":"<p>VBA\u3067Edge\u64cd\u4f5c\u3092\u81ea\u52d5\u5316\u3057\u3066\u307f\u305f\u3002 .NET Framework\u304c\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3055\u308c\u3066\u3044\u306a\u3044\u3068\u3001\u5b9f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":2366,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[34,35],"tags":[],"class_list":["post-2354","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vba","category-vbscript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/oreoreki.gotdns.ch\/wp-content\/uploads\/sites\/2\/2022\/05\/mqdefault-3.jpg","jetpack_shortlink":"https:\/\/wp.me\/p9WqRX-BY","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2354","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2354"}],"version-history":[{"count":12,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2354\/revisions"}],"predecessor-version":[{"id":2449,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/posts\/2354\/revisions\/2449"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=\/wp\/v2\/media\/2366"}],"wp:attachment":[{"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2354"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2354"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/oreoreki.gotdns.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2354"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}