Thursday, February 15, 2007

Scripting Games 2007 - Live Scores

This little script will parse the scores table on the scripting games website and output the results into the console. It is working kinda slow due to some PS inconsistencies regarding IE automation, so I'll have to keep on checking on it . Meanwhile, get your own results ;-)


$ie=new-object -com internetexplorer.application
while($ie.ReadyState -ne 4) {start-sleep -m 500}

$ds = new-object "System.Data.DataSet" $ds.Tables.Add("score")

1..10 | foreach {
    $table = $ie.document.getElementById("E4")
    $trs | foreach {     
        $tds = $_.GetElementsByTagName("TD")     
        $dr = $ds.Tables[0].NewRow()     
        $tds | foreach {$dr[$x] = $_.innerText}     

$ds.tables | ft * -auto


2 comments: said...

Super cool!

Might have a type in the blog post though:

That last "}" doesn't seem to match up with an opening "{".

I changed the line to this in my script:

But the results were much worse.

Shay Levy said...

10x for the feedback Marco.

It seems that PS doesn't work as excepted with HTML Dom.
I even tried to parse some HTML locally...
PS performance is definitely slow!