Jump to content

Can _IELinkGetCollection return links for particular tags?


Recommended Posts

Hello All,

Can anybody please tell me that if _IELinkGetCollection can be used to find links in the particular tags.

Please see my code

$oInputs = _IETagNameGetCollection ($oIE, "LI")
     For $oInput In $oInputs
     MsgBox(0, "UL", $oInput.innerText)
     $oLinks = _IELinkGetCollection($oInput)
     For $oLink In $oLinks
     $str_cmpre = StringCompare($oLink.href,"Null")
     If ($str_cmpre == 0) Then
     Msgbox(0,"Hello", "Hello")
     Else
     Msgbox(0,"Link","Got the link", 1)
     MsgBox(0, "Link Info", $oLink.href, 1)
     EndIf

;~   If( $oLink.href == "Null") Then
;~       Msgbox(0,"Hello", "Hello")
;~       ;msgbox(0,"UL",$oInput.innertext)
;~   Else
;~       Msgbox(0,"Link","Got the link", 1)
;~       MsgBox(0, "Link Info", $oLink.href, 1)
;~   EndIf
     Next

Next

I want to read the tag and find out if the tag has a link within it or not. The above logic does not work. Always the else part of If is been executed.

Today while keenly reading the help i found out that _IELinkGetCollection(ByRef $o_object [, $i_index = -1]) takes input parameter as $o_object which is a Object variable of an InternetExplorer.Application, Window or Frame object.

Can i use the tag name objects as the input parameter with in it.

Please guide me in this respect.

Thanks in Advance.

Link to comment
Share on other sites

Here's an example of how you could possibly approach it, seems to work for me if I'm properly understanding what you are trying to do:

#include <IE.au3>
Local $oIE = _IECreate("http://www.w3.org/QA/Tips/unordered-lists")
;Get collection of elements tagged "LI" for List Item
$oListItems = _IETagNameGetCollection ($oIE, "LI")
For $oListItem In $oListItems
ConsoleWrite("LI (text): " & $oListItem.innerText & @CRLF)
;Get all the elements tagged "a" for Anchor
;This needs an error handler in case the list item
;  doesn't have any anchors
$oAnchors = $oListItem.getElementsByTagName("a")
For $oAnchor In $oAnchors
  ;Get the href of each anchor
  $sHref = $oAnchor.href
  ConsoleWrite("    Link Info: " & $sHref & @CRLF)
    Next
Next
Link to comment
Share on other sites

Here's an example of how you could possibly approach it, seems to work for me if I'm properly understanding what you are trying to do:

#include <IE.au3>
Local $oIE = _IECreate("http://www.w3.org/QA/Tips/unordered-lists")
;Get collection of elements tagged "LI" for List Item
$oListItems = _IETagNameGetCollection ($oIE, "LI")
For $oListItem In $oListItems
ConsoleWrite("LI (text): " & $oListItem.innerText & @CRLF)
;Get all the elements tagged "a" for Anchor
;This needs an error handler in case the list item
; doesn't have any anchors
$oAnchors = $oListItem.getElementsByTagName("a")
For $oAnchor In $oAnchors
;Get the href of each anchor
$sHref = $oAnchor.href
ConsoleWrite(" Link Info: " & $sHref & @CRLF)
Next
Next

Thanks a lot Mr Mitchell. Your code was of great help. It helped me to resolve the issue.

"getElementsByTagName" was the call i had to make instead i was using another API of AutoIT

Thanks once again.

Link to comment
Share on other sites

Thanks a lot Mr Mitchell. Your code was of great help. It helped me to resolve the issue.

"getElementsByTagName" was the call i had to make instead i was using another API of AutoIT

Thanks once again.

It's built-in! ( _IETagNameGetCollection() )

$oAnchors = _IETagNameGetCollection($oListItem, "a")

Use that since error handling is already in there.

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