Jump to content

IE Link object (obtain link text)


Recommended Posts

Just trying to get the text in an <a> tag

<a id="3734" href="#">Tuesday, March 12, 2013</a>

I want to obtain Tuesday, March 12, 2013 from the link.

Given my link object array is $aLinks,

$aLinks = _IELinkGetCollection($oTarget)
for $link in $aLinks
  if StringInStr($link.href, "http://URLtextToSearch") then
    ConsoleWrite($link.text & @CRLF)
  endif
next

at least I thought .text was the correct property but it's not. And my command works as I've tested it with ConsoleWrite($link.href & @CRLF) and $link.id as well

Edited by Mechaflash
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Mechaflash,

I use routines similar to this for debugging sites that I scrape. The source in this example is a simple text file downloaded by inetget.

#include <IE.au3>

local $fln = 'k:\sd\sd0100\nba\boxes\400440940'         ; this is a text file downloaded with inetget

_get_links( fileread($fln) )
ConsoleWrite(@error & @LF)

func _get_links($html)

    Local $o_htmlfile = ObjCreate('HTMLFILE'), $str
    If Not IsObj($o_htmlfile) Then Return SetError(-1)

    $o_htmlfile.open()
    $o_htmlfile.write($html)
    $o_htmlfile.close()

    Local $ocol = _IETagnameGetCollection($o_htmlfile, 'a')
    if not isobj($ocol) then return seterror(-2)

    for $o in $ocol
        ConsoleWrite('innertext = ' & $o.innertext & @LF)
        ConsoleWrite('href      = ' & $o.href & @LF)
        ConsoleWrite('-----------------------' & @LF)
    next

endfunc

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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