Jump to content
Sign in to follow this  
Kinhow

How to get the content of html tag

Recommended Posts

Kinhow

So I already have the DOM element in an object and what I am trying to do is getting the 173 out of this $tagElement

<span class="health-count">173</span>

I tried $tagElement.innnerHTML and innerText but it didnt work.

Sorry if its a dumb question, but I have spent some time on this and could not find anything on the forum.

Share this post


Link to post
Share on other sites
jvds

maybe StringMid or _StringBetween?

$string = '<span class="health-count">173</span>'
$start=StringInStr($string,'<span class="health-count">')+StringLen('<span class="health-count">')
$end=StringInStr($string,'</span>')
$restul = StringMid($string,$start,$end-$start)
ConsoleWrite('$restul='&$restul&@CRLF)

or

#include <String.au3>
$test = _StringBetween($string,'<span class="health-count">','</span>',0)
if IsArray($test) then ConsoleWrite('$test[0]='&$test[0]&@CRLF)

 

Share this post


Link to post
Share on other sites
jguinch

@Kinhow : show your code. There is probably and error with the $tagElement object.

This works :

#Include <IE.au3>

$oIE = _IECreate()

_IEBodyWriteHTML($oIE, '<span class="health-count">173</span>')

$oSpans = _IETagNameGetCollection($oIE, "span")
For $oSpan In $oSpans
    If $oSpan.className = "health-count" Then MsgBox(0, "", $oSpan.innerHtml & @CRLF)
Next

 

Share this post


Link to post
Share on other sites
Kinhow

For somehow innerText was not working, maybe a typo.

 

But now its working fine!

 

$tag.innerText

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  

×