Files
ImportExcel/Public
Matthew Gray 45ed6a06dc [Get-HtmlTable] XPath optimization
```powershell
$rows =    $h.SelectNodes("//table[$TableIndex]//tr")
```
XPath selector in line 53 uses complex expression that can lead to unexpected result. The problem is that HtmlAgilityPack may have specific issues. In particular, on websites containing multiple tables this selector can find not one table. This is aggravated by the fact that tables can have different structures.
To avoid ambiguity this PR suggests to separate queries. Oneliner simplifies error checking
```powershell
$rows = try {
  $h.SelectSingleNode("//table[$TableIndex]").SelectNodes(".//tr")
} catch {}
if (-not $rows) {Write-Warning "Could not find rows for `"//table[$TableIndex]`" in $Url ."}
```
This expression doesn't even need testing, it just works.
2025-04-23 13:36:32 +03:00
..
2019-12-01 17:04:27 +00:00
2024-05-17 23:28:26 -05:00
2020-06-21 22:53:35 +02:00
2022-04-28 19:44:49 -04:00
2022-04-28 19:44:49 -04:00
2019-12-01 17:04:27 +00:00
2022-12-28 14:26:43 -05:00
2023-06-10 15:27:53 -04:00
2022-04-28 19:44:49 -04:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00
2019-12-01 17:04:27 +00:00