WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with MSIE
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Extract Column from HTML Table

Question:

There is a html page that has one table element of 50 rows and 6 columns. I need complete column 3 to be extracted into list or array variable. I need some advice.

Answer:

without seeing the HTML I can only suggest a likely course. Something like this maybe...
   
mycolumn = 3
cellList = browserdoc.GetElementsByTagName("TD")
column3 = ""
For x = 0 To cellList.length-1
   If x+1 mod mycolumn == 0
      thiscell = cellList.item(x)
      column3 = ItemInsert(thiscell.innerText, -1, column3, "|")
      ObjectClose(thiscell)
   EndIf
Next
ObjectClose(cellList)
Message("Debug", column3)

User Response:

; Use MSIE browser to parse a table from within htm file.
oBrowser = ObjectOpen("InternetExplorer.Application")
oBrowser.visible = @FALSE
oBrowser.silent  = @TRUE
oBrowser.offline = @TRUE

oBrowser.navigate(sFileHTM)

While ((oBrowser.busy)||(oBrowser.readystate!=4))
   TimeDelay(1)
EndWhile

oDocument = oBrowser.Document
oListTABLE = oDocument.GetElementsByTagName("TABLE")
iDim1 = oListTABLE.length

; Convert the one and only table in this document into a CSV file.
oTable = oListTABLE.item(0)
oListTR = oTable.GetElementsByTagName("TR")
iDim1 = oListTR.length
iHighDim1 = iDim1-1

For ii=0 To iHighDim1
   sCSV = ""
   oThisTR = oListTR.item(ii)
   oListTD = oThisTR.GetElementsByTagName("TD")
   iDim2 = oListTD.length
   If iDim2
      iHighDim2 = iDim2-1
      For ik=0 To iHighDim2
         oThisTD = oListTD.item(ik)
         sCSV = ItemInsert(StrCat('"',StrTrim(oThisTD.innerText),'"'),-1,sCSV,";")
         ObjectClose(oThisTD)
      Next
      sCSV = StrCat(sCSV,@CRLF)
      udfFilePutAppend(sFileCSV1,sCSV)
   EndIf
   ObjectClose(oListTD)
   ObjectClose(oThisTR)
Next
ObjectClose(oListTR)
ObjectClose(oTable)
ObjectClose(oListTABLE)
ObjectClose(oDocument)

oBrowser.quit
ObjectClose(oBrowser)

Article ID:   W16117
File Created: 2004:03:30:15:42:56
Last Updated: 2004:03:30:15:42:56