【发布时间】:2020-03-12 14:03:11
【问题描述】:
我有以下代码:
$html = New-Object -ComObject "HTMLFile"
$source = Get-Content -Path $FilePath -Raw
try
{
$html.IHTMLDocument2_write($source) 2> $null
}
catch
{
$encoded = [Text.Encoding]::Unicode.GetBytes($source)
$html.write($encoded)
}
$t = $html.getElementsByTagName("table") | Where-Object {
$cells = $_.tBodies[0].rows[0].cells
$cells[0].innerText -eq "Name" -and
$cells[1].innerText -eq "Description" -and
$cells[2].innerText -eq "Default Value" -and
$cells[3].innerText -eq "Release"
}
代码在 Windows Powershell 5.1 上运行良好,但在 Powershell Core 7 上 $_.tBodies[0].rows 返回 null。
那么,如何在 PS 7 中访问 HTML 表格的行?
【问题讨论】:
标签: html powershell powershell-core