Jump to content

How to get a table after a specific div?


olzs00
 Share

Recommended Posts

On my webpage there are several div-tags and there are several tables. None of them have an id or a name. The order of the divs and tables are not fixed which means I cant use _IETableGetCollection() The table I'm trying to get data form is always the first table after the div-tag with .innertext="This is a unique innertext for a div-tagg". See example code below.

<div class="content_bold">This is a unique innertext for a div-tagg</div>
<table class="area_EEEEEE" width="400">
   <tr class="componentHeaderSmall">
      <td>Value1</td>
   </tr>
   <tr class="adminHeader">
      <td>Value2</td>
   </tr>
</table>

How do I find the correct table and how do I write down the value for each td.innertext from the table? I guess need something like this

$tag = _IETagNameGetCollection($oIE, "div")
For $tags In $tag
    If $tags.innertext="This is a unique innertext for a div-tagg" Then
        ;Get The First Table
        ;Write Down Each td.innertext inside the table in my Excelfile useing _Excel_RangeWrite()
Next

Any ideas?

Link to comment
Share on other sites

  • 1 month later...

Sorry for a very late response but thanks to you both for tip on how I can solve it.

I'm pretty sure the code can be written in a more efficient way, but I solved it with the following code

$tag = _IETagNameGetCollection($oIE, "div")
      For $tags In $tag
         If $tags.innertext="This is a unique innertext for a div-tagg" Then        ;Find the right table and thats the one after this div-tag
            Local $oTable = $tags.NextElementSibling
            ExitLoop
         EndIf
      Next
      Local $aTableData = _IETableWriteToArray($oTable, True)   ;true=create a table more like the one on the web-page
      If $iGetSomeData = 1 Then
         _Excel_RangeWrite($oWorkbook, Default, $aTableData[1][1], $ColumnToWriteInfo1In&$i)
         _Excel_RangeWrite($oWorkbook, Default, $aTableData[2][1], $ColumnToWriteInfo2In&$i)
         _Excel_RangeWrite($oWorkbook, Default, $aTableData[3][1], $ColumnToWriteInfo3In&$i)
         _Excel_RangeWrite($oWorkbook, Default, $aTableData[5][1], $ColumnToWriteInfo4In&$i)
         _Excel_RangeWrite($oWorkbook, Default, $aTableData[6][1], $ColumnToWriteInfo5In&$i)
      EndIf

In the code above I know that there will always be 6 values that I want to write down. I had another similar problem with at table that I dont know the number of cells in. I solved that with the following code

$tag = _IETagNameGetCollection($oIE, "div")
            For $tags In $tag
               If $tags.innertext="This is the div-tag above the table" Then        ;Find the right table and thats the one after this div-tag
                  Local $oTableChannelPackages = $tags.NextElementSibling
                  ExitLoop
               EndIf
            Next
            Local $aTableDataChannelPackages = _IETableWriteToArray($oTableChannelPackages, True)       ;true=create a table more like the one on the web page
            Local $iNumberOfChannelPackages = UBound($aTableDataChannelPackages, $UBOUND_ROWS)
            For $iNumberOfColumns = 0 to $iNumberOfChannelPackages-1
                 _Excel_RangeWrite($oWorkbook, Default, $aTableDataChannelPackages[$iNumberOfColumns][0], $ColumnToWriteInfo8In&$i)
                 $i = $i+1
            Next


If someone has a tip how I can re-write the code to make it more efficient you are more than welcome to write a comment. Thanks in advance 🙂

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...