Private/Get-NrcArticle.ps1
function Get-NrcArticle { param ( [Parameter(Mandatory)] [string]$Uri ) Invoke-WebRequest -Uri $Uri ` | Select-Object -ExpandProperty Links ` | Select-Object -ExpandProperty HRef ` | Where-Object { $_ -like '/nieuws/*' } | ForEach-Object { $Url = "https://nrc.nl$($_)" $DateElements = ($Url -split '/')[4..6] $Document = ConvertTo-HtmlDocument -Uri $Url $Body = ($Document | Select-HtmlNode -CssSelector 'div.vorm__article-content p' -All).InnerText $Body = $Body -join ' ' $Body = $Body -replace "`n", ' ' $Body = $Body -replace "`r", ' ' $Body = $Body -replace '\s{2,}', ' ' $Body = $Body -replace 'Lezers zijn de.*$', '' [PSCustomObject][Ordered]@{ PSTypeName = 'UncommonSense.Nrc.Article' Url = $Url Date = Get-Date -Year $DateElements[0] -Month $DateElements[1] -Day $DateElements[2] Title = ($Document | Select-HtmlNode -CssSelector 'h1').InnerText.Trim() Body = $Body Image = ($Document | Select-HtmlNode -CssSelector 'img') | ForEach-Object { $_.GetAttributeValue('src', '') } } } } |