Compare commits

...

5 Commits

Author SHA1 Message Date
Doug Finke
5387c06146 Merge pull request #1695 from scriptingstudio/master
[Get-HtmlTable] XPath optimization
2025-04-23 08:16:05 -04:00
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
dfinke
fa447a745c move llms text to root 2025-04-11 07:10:31 -04:00
dfinke
49affcfba7 add llms text of Examples directort for use in LLMs 2025-04-11 06:51:18 -04:00
dfinke
dc4a5e9db9 chore: Update changelog for version 7.8.10 and acknowledge PR contributions 2024-10-21 19:44:36 -04:00
3 changed files with 5599 additions and 1 deletions

View File

@@ -50,7 +50,9 @@ function Get-HtmlTable {
else {
$h = ConvertFrom-Html -Content $r.Content
if ($TableIndex -is [valuetype]) { $TableIndex += 1}
$rows = $h.SelectNodes("//table[$TableIndex]//tr")
$rows = try {
$h.SelectSingleNode("//table[$TableIndex]").SelectNodes(".//tr")
} catch {}
if (-not $rows) {Write-Warning "Could not find rows for `"//table[$TableIndex]`" in $Url ."}
if ( -not $propertyNames) {
if ( $tableHeaders = $rows[$FirstDataRow].SelectNodes("th")) {

View File

@@ -1,3 +1,7 @@
# 7.8.10
- Thank you https://github.com/evenmartinsen for the PR to fix the AV
# 7.8.9
- Thanks to (Edward Miller)[https://github.com/edwardmiller-mesirow] for improving `ConvertTo-ExcelXlsx`and making it more robust

5592
llms-examples.txt Normal file

File diff suppressed because it is too large Load Diff