Jump to content
Sign in to follow this  
tonyrocks

Retrieving Span Title Attribute Value

Recommended Posts

tonyrocks

I am in need of hitting a website to check the value of a span tag title attribute.  I'm pulling my hair out trying to figure out the best way of doing this.  I need to hit this page (just as an example)

http://www.tonyrocks.com/fit/guess.htm

which contains this:

<html>
<body><div class="body">Hey there, this is a test!
<span class="logo" title="this is the logo area"><img src="http://www.tonyrocks.com/logo.png"></span></div>
</body>
</html>

I just need to grab the text 'this is the logo area' and store it in a variable ($spanTitle for example) and then use it with the rest of my script.

I don't want to over complicate it, not sure if I use curl, InetGet or what or even how to start with the AutoIt code.   

Thanks as usual!

-tony

 

Share this post


Link to post
Share on other sites
kylomas

tonyrocks,

 I don't want to over complicate it

local $SpanTitle = 'this is the logo area'

The URL you specified does not have a title.  Run the following...

#include <IE.au3>
#include <array.au3>

Local $oIE = _IECreate("http://www.tonyrocks.com/fit/guess.htm", 0, 0, 1, 0)
;Local $oIE = _IECreate("http://www.tonyrocks.com", 0, 0, 1, 0)

Local $ospans = _IETagNameGetCollection($oIE, 'span')
if isobj($ospans) then
    For $ospan In $ospans
        if isobj($ospan) then
            ConsoleWrite($ospan.outerhtml & @LF)
        endif
    Next
Else
    ConsoleWrite('No span objects returned' & @LF)
    Exit
endif

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

Share this post


Link to post
Share on other sites
Malkey

I am in need of hitting a website to check the value of a span tag title attribute.  I'm pulling my hair out trying to figure out the best way of doing this.  I need to hit this page (just as an example)

http://www.tonyrocks.com/fit/guess.htm

which contains this:

<html>
<body><div class="body">Hey there, this is a test!
<span class="logo" title="this is the logo area"><img src="http://www.tonyrocks.com/logo.png"></span></div>
</body>
</html>

I just need to grab the text 'this is the logo area' and store it in a variable ($spanTitle for example) and then use it with the rest of my script.

I don't want to over complicate it, not sure if I use curl, InetGet or what or even how to start with the AutoIt code.   

Thanks as usual!

-tony

Your link, http://www.tonyrocks.com/fit/guess.htm, is missing an equal sign after title in its source (<span class="logo" title"This is the logo area") .

That's why this trial example works. 

And that's why I couldn't get an example to work on your link.

#include <IE.au3>

Local $Source = _
        '<html>' & @CRLF & _
        '<body><div class="body">Hey there, this is a test!' & @CRLF & _
        '<span class="logo" title="this is the logo area"><img src="http://www.tonyrocks.com/logo.png"></span></div>' & @CRLF & _
        '</body>' & @CRLF & _
        '</html>'

Local $oIE = _IECreate("about:blank", 0, 0, 1, 0)
_IEBodyWriteHTML($oIE, $Source)

Local $ospans = _IETagNameGetCollection($oIE, 'span')
If IsObj($ospans) Then
    For $ospan In $ospans
        If IsObj($ospan) Then
            $spanTitle = $ospan.title
        EndIf
    Next
Else
    $spanTitle = 'No span objects returned'
    Exit
EndIf

MsgBox(0, "Results", $spanTitle)

Share this post


Link to post
Share on other sites
tonyrocks

OH great!  I'm on the right path.  I've fixed the source of guess.htm.  This solutions works for me, except for one thing, I will have multiple span tags with titles.  The one I want to retrieve in particular has a class attribute value of logo.  For example:

<html>
<body><div class="body">Hey there, this is a test!
<span class="logo" title="this is the logo area"><img src="http://www.tonyrocks.com/logo.png"></span></div>
<span class="secondary" title="secondary">this is all secondary</span></div>
</body>
</html>

Thanks!

Share this post


Link to post
Share on other sites
tonyrocks

ok! I've got it.  I did this:

#include <IE.au3>

Local $oIE = _IECreate("http://www.tonyrocks.com/fit/guess.htm", 0, 0, 1, 0)
Local $ospans = _IETagNameGetCollection($oIE, 'span')

For $ospans In $ospans

If $ospans.className == "logo" Then
  MsgBox(0, "suceed", $ospans.title);
EndIf

Next

So yes, technically it works, but I think the loop is overkill :)

Edited by tonyrocks

Share this post


Link to post
Share on other sites
kylomas

So yes, technically it works, but I think the loop is overkill

 

Possibly, in such a small app it hardly matters.  You can directly access the object by inidex if you know the relative placement.  Check out  IETagNameGetCollection in the Help file.

kylomas

  • Like 1

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

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  

×