adamchapman

getElementbyTagName() returning nothing

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to scrape the live score of a soccer game contained within the html source snippet below:

...

<div class="bf-col-19-24 inplay" ng-class="sportsHeaderCtrl.data.event.status == 'Finished' ? 'finished' : 'inplay'" ng-if="sportsHeaderCtrl.data.hasScores"><!----><ng-include src="'app/modules/sports-header/source/views/partials/sports/avb.html'"><!----><div ng-if="sportsHeaderCtrl.data.hasScores"><div class="title avb"><span title="LD Alajuelense">LD Alajuelense</span> <span class="score" ng-class="{ finished: sportsHeaderCtrl.data.event.status == 'Finished' }">0-1</span> <span title="CD Olimpia">CD Olimpia</span></div></div><!----><!----></ng-include><p class="time-elapsed inplay" ng-class="{ inplay: sportsHeaderCtrl.data.event.status !== 'Finished' }"><!----> <!----><span ng-if="!sportsHeaderCtrl.data.moduleConfig.eventStatus[sportsHeaderCtrl.data.event.status]">50'</span><!----><halftime-fulltime status="sportsHeaderCtrl.data.event.status" score="sportsHeaderCtrl.data.event.score" eventtypeid="sportsHeaderCtrl.data.event.eventTypeId"><!----><span class="halftime-fulltime" ng-if="data.results">(<!----><span ng-repeat="result in data.results">HT 0-1</span><!---->)</span><!----></halftime-fulltime></p></div>

...


I can see that the score (1-0) is contained in the  <span class="score"> element.  

Copying the method from rootx's post here, I have:
 

Local $oIE = _IECreate("https://www.betfair.com/exchange/plus/football/market/1.133040513?group-by=time", 0, 1 ,1,0)

$target = ""

$tags = $oIE.document.GetElementsByTagName("span")

ConsoleWrite("-- $oIE.document.GetElementsByTagName --" & $tags & @CR)


For $tag in $tags
$class_value = $tag.GetAttribute("class")

consolewrite("class " & string($class_value) & @CRLF)

If string($class_value) = "score" Then
    $target = $tag
        ConsoleWrite("Tag Found " & $target.outerText & @CRLF)
    ExitLoop

EndIf
Next

_IEQuit ($oIE)

Unfortunately, $tags appears to be empty because the first consoleWrite command only prints "-- $oIE.document.GetElementsByTagName --", with nothing else on the row.

If anybody can offer a hint to get this working it would be really helpful.

Thanks!

 

Edited by adamchapman

Share this post


Link to post
Share on other sites



#2 ·  Posted

$tags is a collection. This can't be printed by ConsoleWrite   :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

I think the problem is that you simply dont give enough time to IE to load ;)

This is working for me:

#include <IE.au3>
#include <MsgBoxConstants.au3>

$oIE = _IECreate("https://www.betfair.com/exchange/plus/football/market/1.133040513?group-by=time", 0, 1 ,1)

SplashTextOn("","waiting for page to load")

sleep(10000)

SplashOff()

$spans = _IETagNameGetCollection($oIE, "span")

For $span In $spans
    If $span.className = "score" Then
        MsgBox(0, "text", $span.innerText)
    EndIf
Next

 

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