Private/Get-VolkskrantCartoon.ps1
function Get-VolkskrantCartoon { param ( [Parameter(Mandatory)] [string]$Uri, [Parameter(Mandatory)] [string]$Title ) $DutchCulture = New-Object -TypeName System.Globalization.CultureInfo -ArgumentList 'nl-NL' $Content = Invoke-WebRequest -Uri $Uri | Select-Object -ExpandProperty Content $Document = $Content | ConvertTo-HtmlDocument $Images = $Document | Select-HtmlNode -CssSelector 'img' -All $Date = Get-Date $Images | Where-Object { $_.Attributes['src'].Value } | ForEach-Object { $DateNode = $_.ParentNode.ParentNode.PreviousSibling $DateText = $DateNode.InnerText.Trim() $Date = switch -Regex ($DateText) { '^\d+\s+\w+\s+\d+$' { [DateTime]::ParseExact($_, 'd MMMM yyyy', $DutchCulture); break; } '^\d+\s+\w+$' { [DateTime]::ParseExact($_, 'd MMMM', $DutchCulture); break; } default { $Date.AddDays(-1); break; } } [PSCustomObject][Ordered]@{ PSTypeName = 'UncommonSense.Volkskrant.Article' Url = $_.Attributes['src'].Value Date = $Date Title = $Title Body = $_.Attributes['src'].Value } } } |