Jump to content

HTML table parser not producing expected results


jbnv
 Share

Recommended Posts

; $oTable: HTML <table> element
Func IterateTableRows(ByRef $oTable)
   For $oTr In $oTable.rows
      Sleep(1000)
      ConsoleWrite("(" & $oTr.className & ") ")
      If Not ($oTr.className = "tblGridView_row1" Or $oTr.className = "tblGridView_row2") Then ContinueLoop
      ... ; following details omitted
   Next
EndFunc

The purpose of this code is to process the rows of the class "tblGridView_row1" or "tblGridView_row2." It's not doing that. Given the following table (simplified for brevity):

<table>
  <tbody>
    <tr align="center" class="tblGridView_header">...</tr>
    <tr class="tblGridView_row1">...</tr>
    <tr class="tblGridView_row2">...</tr>
    <tr class="tblGridView_row1">...</tr>
    <tr class="tblGridView_row2">...</tr>
    <tr class="tblGridView_row1">...</tr>
    <tr class="tblGridView_row2">...</tr>
    <tr class="pagination">...</tr>
  </tbody>
</table>

The ConsoleWrite call should output "(tblGridView_header) (tblGridView_row1) (tblGridView_row2) (tblGridView_row1) (tblGridView_row2) (tblGridView_row1) (tblGridView_row2) (pagination)". But instead the output is "(tblGridView_header) (tblGridView_row1) () () () () () ".

What is happening here and how do I fix it?

Link to comment
Share on other sites

Using the provided code it works for me

#include <IE.au3>

Local $oIE = _IECreate()
$oIE.visible = 0
Local $sHTML = FileRead("1.html")
_IEBodyWriteHTML($oIE, $sHTML)

Sleep(100)
$oTable = _IETableGetCollection($oIE, 0)
IterateTableRows($oTable)

; $oTable: HTML <table> element
Func IterateTableRows(ByRef $oTable)
   For $oTr In $oTable.rows
      Sleep(1000)
    ;  ConsoleWrite("(" & $oTr.className & ") ")
      If Not ($oTr.className = "tblGridView_row1" Or $oTr.className = "tblGridView_row2") Then ContinueLoop
       ; following details omitted
      ConsoleWrite("(" & $oTr.className & "-test) ")
   Next
EndFunc

 

Link to comment
Share on other sites

Looking at it again, I realized that the code that I omitted does a postback, which surely destroys the table object that I am trying to read. So what I need to do is make a hard copy of the table parameter and iterate over that.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...