Jump to content

Extract OnClick links on TR (without name)


Recommended Posts

Please i need help.

I have a page and i need to extract all the onlick's links inside X <tr> and put in an array.

These tr's have only alternating 2 types of class and NO NAME.

I have tried several methods without success .. 

Please anyone can help?

What _IE functions is adapt for this problem?

I put an example:

<table id="rounded-corner" summary="List" border="1" cellpadding="0" cellspacing="0">
            <tr class="r1 link highlight" title="" onclick="location.href='link.aspx?codeid=0111'">
            <td>
                INFO  
            </td>
            <td title="INFO">INFO ...</td>              
                <td>11/07/2013</td> 
                <td>11/07/2013</td> 
                <td title="INFO2">INFO2</td>
                <td style="text-align:center"><font color='Green'><b>6</b></font></td>
                <td style="text-align:center" title="Normal"><img src='2.gif'/></td>
            </tr>

            <tr class="r2 link highlight" title="" onclick="location.href='link.aspx?codeid=0112'">
            <td>
                INFO  
            </td>
            <td title="INFO">INFO ...</td>              
                <td>11/07/2013</td> 
                <td>11/07/2013</td> 
                <td title="INFO2">INFO2</td>
                <td style="text-align:center"><font color='Green'><b>6</b></font></td>
                <td style="text-align:center" title="Normal"><img src='2.gif'/></td>
            </tr>   

            <tr class="r1 link highlight" title="" onclick="location.href='link.aspx?codeid=0113'">
            <td>
                INFO  
            </td>
            <td title="INFO">INFO ...</td>              
                <td>11/07/2013</td> 
                <td>11/07/2013</td> 
                <td title="INFO2">INFO2</td>
                <td style="text-align:center"><font color='Green'><b>6</b></font></td>
                <td style="text-align:center" title="Normal"><img src='2.gif'/></td>
            </tr>

            <tr class="r2 link highlight" title="" onclick="location.href='link.aspx?codeid=0114'">
            <td>
                INFO  
            </td>
            <td title="INFO">INFO ...</td>              
                <td>11/07/2013</td> 
                <td>11/07/2013</td> 
                <td title="INFO2">INFO2</td>
                <td style="text-align:center"><font color='Green'><b>6</b></font></td>
                <td style="text-align:center" title="Normal"><img src='2.gif'/></td>
            </tr>
</table>

so i need to extract from that example code:

$array = ('link.aspx?codeid=0111','link.aspx?codeid=0112','link.aspx?codeid=0113','link.aspx?codeid=0114')

Please help!

Thanks!

Edited by nasty
Link to comment
Share on other sites

  • Moderators

#include <IE.au3>

$sURL = ""
$sTableId = "rounded-corner"

_IEErrorHandlerRegister()
$oIE = _IECreate($sURL)
; get reference to the table by id
$oTable = _IEGetObjById($oIE, $sTableId)
; get a collection of all table rows
$oTableRows = _IETagNameGetCollection($oTable, "TR")
; enumerate through the collection
For $oTableRow In $oTableRows
    ; get the value of the onclick attribute
    $sOnClickValue = $oTableRow.getAttribute("onclick")
    ConsoleWrite($sOnClickValue & @CRLF)
Next

Link to comment
Share on other sites

  • Moderators

The previous code I posted fails to return the attribute on some pages. The following works instead:

#include <IE.au3>

$sURL = ""
$sTableId = "rounded-corner"

_IEErrorHandlerRegister()
$oIE = _IECreate($sURL, 1)
; get reference to the table by id
$oTable = _IEGetObjById($oIE, $sTableId)
; get reference to the table body
$oTableBody = _IETagNameGetCollection($oTable, "TBODY", 0)
; get a collection of all rows in the table body
$oTableRows = _IETagNameGetCollection($oTableBody, "TR")
; enumerate through the collection
For $oTableRow In $oTableRows
    ; get a collection of attributes for the current table row
    $oAttributes = $oTableRow.attributes
    ; enumerate through the collection
    For $oAttribute In $oAttributes
        ; search for the onclick attribute
        If String($oAttribute.name) = "onclick" Then
            ; return the value of found attribute
            ConsoleWrite($oAttribute.value & @CRLF)
        EndIf
    Next
Next
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...