I’m a sports fan, and also have aspirations of getting better at parsing web output with PowerShell. I’m trying to get each NFL team and some various team stats based on the table in this link:
http://www.sportingcharts.com/nfl/stats/points-for-and-against/2016/
So far I am able to get the table info with the following:
$HTML = Invoke-WebRequest "http://www.sportingcharts.com/nfl/stats/points-for-and-against/2016/" $Chart = $HTML.AllElements | where{$_.class -match "table table-striped table-bordered table-hover tablesaw-swipe"} $Table = $chart.outerHTML
The issue I am having is how to then loop through and essentially come up with an array/hashtable/PSCustomObject that would have “Team,Pts,PtsAgainst,Diff,PPG,PPGAgainst,PPGDiff”. The end goal is to be able to query a team and get the pts information from the array/hashtable/customobject.
With XML I am able to fudge my knowledge a little bit because you can enumerate through it and see each step and what data is available. Attempting a similar process with the above code does not work. $Table is just a string and I’m not sure a way to marry the info to the parent ‘Team’, etc. I have not tried casting the object types, as I’m very new to HTML/JSON formatting.
Any help is appreciated.
submitted by /u/gorlechov
[link] [comments]
The post Parsing Invoke-WebRequest appeared first on How to Code .NET.