IE操作
機能
Internet Explorerを起動し、Google検索を実行する。
前提
- Internet Explorerがインストールされていること。
ソースコード
ScrennLogin.vbs
Option Explicit '引数のチェック if WScript.Arguments.Count < 2 then WScript.echo("too few arguments.") WScript.Quit(-1) end if Dim url url = WScript.Arguments(0) Dim researchWord researchWord = WScript.Arguments(1) if (Len(url) < 0) then WScript.echo("URL is not set.") WScript.Quit(-1) end if if (Len(researchWord) < 0) then WScript.echo("research word is not set.") WScript.Quit(-1) end if use_ie ' IE用 Subプロシージャ Sub use_ie() Dim ie ' IE用変数 Set ie = CreateObject("InternetExplorer.Application") ' IE起動 ie.Navigate url ' URL ie.Visible = True ' IEの可視化 waitIE ie ' IEの起動待機 ' キーワード入力 ie.Document.getElementById("lst-ib").Value = researchWord WScript.Sleep 1000 ' 検索ボタンクリック ie.Document.all("btnG").Click End Sub ' IEがビジー状態の間待ちます Sub waitIE(ie) Do While ie.Busy = True Or ie.readystate <> 4 WScript.Sleep 1000 Loop End Sub
実行.bat
@echo off set URL=https://www.google.co.jp/ set RESEARCH_WORD=abc cscript ScrennLogin.vbs %URL% %RESEARCH_WORD%