Getting Excuses Automatically

by Aug 10, 2018

Invoke-WebRequest can retrieve HTML info from web pages, and regular expressions can then scrape information from these pages.

Here is some code that gets you excuses in English:

$ProgressPreference = 'SilentlyContinue'

$url = "http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl?$(Get-Random)"
$page = Invoke-WebRequest -Uri $url -UseBasicParsing
$pattern = '(?s)<br><font\ size\ =\ "\+2">(.{1,})</font'
if ($page.Content -match $pattern)
{
  $matches[1].Trim() -replace '\n', '' -replace '\r', ''
}

And this would get you mixed excuses in English and German:

$page= Invoke-WebRequest "http://www.netzmafia.de/cgi-bin/bofhserver.cgi"
$pattern='(?s)<B>(.*?)</B>'
if ($page.Content -match $pattern)
{
  $matches[1].Trim() -replace '\n', '' -replace '\r', ''
}

Twitter This Tip! ReTweet this Tip!