Skip to content

Instantly share code, notes, and snippets.

@jwmoss
Forked from JustinGrote/Get-HTMLTable.ps1
Created September 18, 2020 06:59
Show Gist options
  • Save jwmoss/188023b09bc676739a7c1fd29afa9047 to your computer and use it in GitHub Desktop.
Save jwmoss/188023b09bc676739a7c1fd29afa9047 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