Last active
September 18, 2020 06:59
-
-
Save JustinGrote/a80dc7244299f82767b4e4156e14a1d4 to your computer and use it in GitHub Desktop.
Get-HTMLTable Prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using namespace HtmlAgilityPack | |
function Get-HTMLTable { | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory,ValueFromPipeline)][HtmlNode]$HtmlDocument | |
) | |
process { | |
foreach ($table in $HtmlDocument.SelectNodes('//table')) { | |
Write-Verbose "Found Table $($table.id)" | |
$headers = $table.SelectNodes('//thead/tr/th').InnerText | |
foreach ($row in $table.SelectNodes('//tbody/tr')) { | |
$rowResult = [Ordered]@{} | |
$i=0 | |
$columns = $row.childnodes.where{$_.name -eq 'td'}.InnerText | |
foreach ($headerItem in $headers) { | |
$rowResult[$headerItem] = $columns[$i] | |
$i++ | |
} | |
[PSCustomObject]$rowResult | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment