I have the following problem:
I use a PS script that scrapts a web page. Based on the response, it concludes if the site is up or down.
My code works
foreach ($site in $websitesArray) {
$Counter = 5
$ErrorCounter = 0
if ($site -like 'http://*') {
$siteSplit = $site.Replace("http://", "")
}
else {
$siteSplit = $site.Replace("https://", "")
}
$ip = [System.Net.Dns]::GetHostAddresses($siteSplit)
for (int i = 0 ; i -lt $Counter ; i++) {
Try {
$HTMLstring = $web.DownloadString($site)
}
Catch {
$ErrorCounter++
}
Start-Sleep 5s
}
if ($ErrorCounter > 3) {
$body += "The website " + $site + " (" + $ip + ") has returned an HTTP error and is down <br />"
}
}
The problem is that the following is returned for pages that have a Cookie Policy pop up:
The remote server returned an error: (500) Internal Server Error.
What workaround could I use to prevent this false positive from happening? Keep in mind that I have a list of websites so a hardcoded solution wouldn't be helping me.