Skip to content

Instantly share code, notes, and snippets.

@tackme31
Last active June 30, 2021 09:53
Show Gist options
  • Select an option

  • Save tackme31/18bef14604d89cc27be180760ef419c2 to your computer and use it in GitHub Desktop.

Select an option

Save tackme31/18bef14604d89cc27be180760ef419c2 to your computer and use it in GitHub Desktop.
Compare HTML fetched by the Invoke-WebRequest command with each other.
function Get-HtmlContent($url)
{
Invoke-WebRequest $url `
| Select-Object -ExpandProperty Content `
| ForEach-Object {$_.Split([Environment]::NewLine, [StringSplitOptions]::RemoveEmptyEntries)}
}
function Compare-WebResponse($url1, $url2) {
$html1 = Get-HtmlContent $url1
$html2 = Get-HtmlContent $url2
Compare-Object $html1 $html2
}
### Example ###
$hasDiff = Compare-WebResponse "https://example.com/foo" "https://example.com/bar"
if ($hasDiff) {
echo "Has defference."
}
else {
echo "No defference."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment