Home » Interview Questions, Javascript & Libraries, Web 3.0 » VBScript Fetch and show the content of an HTML Table from a web page


Someone wanted the code written in VBScript, which would fetch the content of a webpage, grab the html table with a specific identifier from it, and print all the text in its cells. This script loads an instance of Internet Explorer in the background and asks it to load a webpage. We can then grab any DOM element on the page using Document.getElementById(). After accessing the table object, it loops through the rows and columns and appends the cell text to a string to finally print it. The example fetches a table from the webpage hosted here, http://anees.amoeba.co.in/table.html. The ID of the table is ‘daTable’.

Dim Browser,strOut
Set Browser = CreateObject("InternetExplorer.Application")
With Browser
  .Visible = False
  .Navigate "http://anees.amoeba.co.in/table.html"
'Wait for Browser
  Do While .Busy
    WScript.Sleep 100
End With
Set daTable = Browser.Document.getElementById("daTable")
strOut = ""
For i = 0 To daTable.rows.length - 1
  For j = 0 To daTable.rows.item(i).cells.length - 1
    strOut = strOut & daTable.rows.item(i).cells.item(j).innerText & Chr(9)
  strOut = strOut & Chr(13) & Chr(10)
Browser = Null
Msgbox "Table Data: " & Chr(13) & Chr(10) & strOut

Copy the code in to a Text Editor and save the file as .vbs. Run the file in Windows by double clicking it.

Tags: , , , , ,

1 Comment

  1. Guest says:

    The above code was really helpful to read the content of webtable.
    i want to know if the web table doesn’t exists how to handle the code and print table doesn’t exists

Leave a Reply

Page optimized by WP Minify WordPress Plugin