Share this page 

Extract data from HTML pageTag(s): WSH VBScript


theURL = "www.rgagnon.com/masters/wsh-vbs.html"

with CreateObject("InternetExplorer.Application")
  .Navigate("http://" & theURL)
  Do until .ReadyState = 4 
     WScript.Sleep 50 
  Loop
  With .document
    set theTables = .all.tags("table")
    nTables = theTables.length
    for each table in theTables
      s = s & table.rows(0).cells(0).innerText _
        & vbNewLine & vbNewLine
    next
    wsh.echo "Number of tables:", nTables, vbNewline
    wsh.echo "First table first cell:", s
    ' get the data with an ID
    ' msgbox ie.document.getelementbyid("d1").innerHtml
  End With
End With
Output is :
>cscript ieextract.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. Tous droits réservés.

Number of tables: 1

First table first cell: VBScript