Skip to content

Instantly share code, notes, and snippets.

@JustinGrote
Last active September 18, 2020 06:59
Show Gist options
  • Save JustinGrote/a80dc7244299f82767b4e4156e14a1d4 to your computer and use it in GitHub Desktop.
Save JustinGrote/a80dc7244299f82767b4e4156e14a1d4 to your computer and use it in GitHub Desktop.
Get-HTMLTable Prototype
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