[CmdletBinding()]
param(
[string]$Url = 'http://127.0.0.1:8000/',
[switch]$Json
)
$ErrorActionPreference = 'Stop'
try {
$page = Invoke-WebRequest -Uri $Url -UseBasicParsing
} catch {
Write-Error ("Page failed: {0}" -f $_.Exception.Message)
exit 1
}
$html = $page.Content
$images = [regex]::Matches($html, ']*>', 'IgnoreCase')
$missingAlt = @($images | Where-Object { $_.Value -notmatch '\balt\s*=' }).Count
$emptyLinks = [regex]::Matches($html, ']*>\s*', 'IgnoreCase').Count
$ids = [regex]::Matches($html, '\bid\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase') | ForEach-Object { $_.Groups[1].Value }
$duplicateIds = @($ids | Group-Object | Where-Object { $_.Count -gt 1 })
$missingLabel = 0
$inputs = [regex]::Matches($html, ']*>', 'IgnoreCase')
foreach ($field in $inputs) {
if ($field.Value -match 'type\s*=\s*["''](hidden|submit|button|reset|image)["'']') {
continue
}
$idMatch = [regex]::Match($field.Value, 'id\s*=\s*["'']([^"'']+)["'']', 'IgnoreCase')
if (-not $idMatch.Success) {
$missingLabel++
continue
}
$escaped = [regex]::Escape($idMatch.Groups[1].Value)
if ($html -notmatch ('for\s*=\s*["'']' + $escaped + '["'']')) {
$missingLabel++
}
}
$checks = [ordered]@{
lang = [regex]::IsMatch($html, ']+lang\s*=', 'IgnoreCase')
title = [regex]::IsMatch($html, '