Sign in to follow this  
Followers 0
BreCalmor

Pulling Text from between a SPAN tag (no ID)

5 posts in this topic

I was wondering if someone had an idea how to get:

QI_CDFGDC

from:

<SPAN style="COLOR: #fd5962">QI_CDFGDC</SPAN>

Thanks !!

Bre

Share this post


Link to post
Share on other sites



_StringBetween($string, ">", "</")


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

$oText = _IETagNameGetCollection ($oIE, "SPAN", 1)
$sQuizCode = _IEPropertyGet ($oText, "innerhtml")

This is basic, I know, but it worked to get the code.

Bre

Share this post


Link to post
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
Sign in to follow this  
Followers 0