Jump to content

Pulling Text from between a SPAN tag (no ID)


Recommended Posts

If it is the only SPAN tag in the document or one that is easy to find e.g. follows a certain internal format, then you could do something like this:

$oLinks = _IETagNameGetCollection ($oIE, "a")
$Count = 1
    For $oLink in $oLinks
        $StringLeft = StringLeft($oLink.innerHTML, 5)
        If $StringLeft = "<H3>9" Then
            $String = $oLink.outerHTML
            $StringSplit = StringSplit($String, "<H3>", 1)
            $StringSplit2 = StringSplit($StringSplit[1], '"')
            $oURL2 = "http://192.168.1.6:81/" & $StringSplit2[2]
            _IENavigate($oIE, $oURL2, 1)
            sleep(5000)
            ExitLoop
        ElseIf $StringLeft = "<H3>8" Then
            $String = $oLink.outerHTML
            $StringSplit = StringSplit($String, "<H3>", 1)
            $StringSplit2 = StringSplit($StringSplit[1], '"')
            $oURL2 = "http://192.168.1.6:81/" & $StringSplit2[2]
            _IENavigate($oIE, $oURL2, 1)
            sleep(5000)
            ExitLoop
        Else
            ; Do nothing
        EndIf

This extracts all of the A tags then takes the first 5 characters of the HTML inside and checks to see if this <H3>9 or 8. (Could be done with span just change A to SPAN)

If it is then we take the whole HTML string including the a href tags, split the string at <H3> and then splits part of the resulting strings to extract the end of the link (4 numbers in our case) and then use this to navigate to a new webpage using those 4 numbers.

So we effectively go like this:

Step one is to check to see if the HTML inside of the A tag is <H3>9 or <H3>8 in this case it is:

<a href="/inventory/3853/"><h3>910-00733 Unknown DANE-ELEC D1D400 (Unknown)</h3></a>

We then split the <h3> part leaving us with an array like so:

1) <a href="/inventory/3853/">
2) 910-00733 Unknown DANE-ELEC D1D400 (Unknown)</h3></a>

Then we split part (1) up using " leaving us with:

1) <a href=
2) /inventory/3853/
3) >

Then attach number 2 to the URL and move to that page

Hope that helps

Regards,

Adam Mallinson

DOT-COMmunications

Link to comment
Share on other sites

How about just using:

#include <IE.au3>

; ...

$oSpan = _IETagNameGetCollection($oForm, "span", 0) ; 0-based index
$sText = $oSpan.innerText
MsgBox(64, "Results", "Text = " & $sText)

If you don't know the 0-based index of the particular span, then you'll have to get more detailed about WHICH span tag you are interested in.

;)

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...