Skip to content

Instantly share code, notes, and snippets.

@stelf
Created December 13, 2021 15:17
Show Gist options
  • Save stelf/2cd411b7e2ddf10c6876f17c79d92aea to your computer and use it in GitHub Desktop.
Save stelf/2cd411b7e2ddf10c6876f17c79d92aea to your computer and use it in GitHub Desktop.
workaround the querySelectorAll bug that shows when calling it from COM+
$comDoc = New-Object -Com 'HTMLFile'
# load the wiki content
$res = Invoke-WebRequest $webLocation
# create a webview
$comDoc.Write( [System.Text.Encoding]::Unicode.GetBytes($res.Content) )
# query DOM
$elems = $comDoc.querySelector('table.prettytable')
# unfortunately querySelectorAll fails for various reasons
# so we have to enumerate the items manually
$codes = $elems.childNodes().item(0).childNodes() `
| ForEach-Object {
$_.ChildNodes().item(5).innerText -match '(\w+)(?:\sor\s(\w+))*';
($matches[1], $matches[2]) } `
| Sort-Object | Get-unique
$codes -notmatch 'File' -join ' ' | Write-Host
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment