#概要
InternetExplorerをVBScript経由でクローラー化するサンプルを記述する。
Google検索を自動で行い、HTMLを取得する。
職場でも安心バッチ実行できるね。
#コード
IE.bat
CScript IE.vbs > LOG.txt
IE.vbs
Option Explicit
Private Const URL_TARGET = "http://google.co.jp/"
Private Const TIME_MINIMUMWAIT = 1500
Private Const TIME_MAXWAIT = 3000
Main
Public Sub Main()
Dim ie
Dim doc
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
IENavigate ie, URL_TARGET
Set doc = ie.document
With doc
.getElementById("gbqfq").Value = "google"
.getElementById("gbqfba").Click
End With
IEWaitReady ie
WScript.echo doc.Body.InnerHtml
ie.Quit
Set doc = Nothing
Set ie = Nothing
End Sub
Public Sub IENavigate(ByRef ie, ByVal url)
ie.navigate url
IEWaitReady ie
IEWaitRandom
End Sub
Public Sub IEWaitReady(ByRef ie)
Do While ie.Busy = True Or ie.readyState <> 4
WScript.Sleep 100
Loop
IEWaitRandom
End Sub
Public Sub IEWaitRandom()
Dim milliseconds
milliseconds = -1
Do While milliseconds < TIME_MINIMUMWAIT
milliseconds = Int(Rnd * TIME_MAXWAIT)
Loop
WScript.Sleep milliseconds
End Sub