tonyrocks Posted February 19, 2014 Share Posted February 19, 2014 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 Link to comment Share on other sites More sharing options...
kylomas Posted February 19, 2014 Share Posted February 19, 2014 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 Link to comment Share on other sites More sharing options...
Malkey Posted February 20, 2014 Share Posted February 20, 2014 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) Link to comment Share on other sites More sharing options...
tonyrocks Posted February 20, 2014 Author Share Posted February 20, 2014 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! Link to comment Share on other sites More sharing options...
tonyrocks Posted February 21, 2014 Author Share Posted February 21, 2014 (edited) 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 February 21, 2014 by tonyrocks Link to comment Share on other sites More sharing options...
Solution kylomas Posted February 21, 2014 Solution Share Posted February 21, 2014 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 tonyrocks 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now