Last active
June 30, 2021 09:53
-
-
Save tackme31/18bef14604d89cc27be180760ef419c2 to your computer and use it in GitHub Desktop.
Compare HTML fetched by the Invoke-WebRequest command with each other.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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