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 ;-)
[string]$url="http://www.microsoft.com/technet/scriptcenter/funzone/games/games07/psascores.mspx"
$ie=new-object -com internetexplorer.application
$ie.visible=$true
$ie.navigate($url)
while($ie.ReadyState -ne 4) {start-sleep -m 500}
$ds = new-object "System.Data.DataSet" $ds.Tables.Add("score")
[void]$ds.Tables[0].Columns.Add("Name",[string])
[void]$ds.Tables[0].Columns.Add("Country",[string])
1..10 | foreach {
[void]$ds.Tables[0].Columns.Add("e$_",[string])}
[void]$ds.Tables[0].Columns.Add("Total",[string])
$table = $ie.document.getElementById("E4")
$trs=$table.GetElementsByTagName("TR")
$trs | foreach {
$tds = $_.GetElementsByTagName("TD")
$x=0
$dr = $ds.Tables[0].NewRow()
$tds | foreach {$dr[$x] = $_.innerText}
$x++
}
}
$ds.Tables[0].Rows.Add($dr)
$ds.Tables[0].rows[0].delete()
$ds.tables | ft * -auto
$hay
2 comments:
Super cool!
Might have a type in the blog post though:
$ds.Tables[0].Rows.Add($dr)}
That last "}" doesn't seem to match up with an opening "{".
I changed the line to this in my script:
$ds.Tables[0].Rows.Add($dr)
But the results were much worse.
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!
Cheers!
Post a Comment