Getting an Excuse

by Feb 17, 2016

Here is a quick way of getting a good excuse – provided you have Internet access:

#requires -Version 3
function Get-Excuse
{
  $url = 'http://pages.cs.wisc.edu/~ballard/bofh/bofhserver.pl'
  $ProgressPreference = 'SilentlyContinue'
  $page = Invoke-WebRequest -Uri $url -UseBasicParsing
  $pattern = '(?m)<br><font size = "\+2">(.+)'
  if ($page.Content -match $pattern)
  {
    $matches[1]
  }
}

It illustrates how you can use Invoke-WebRequest to download the HTML content of a webpage, then use regular expressions to scrape content from that page.

Twitter This Tip! ReTweet this Tip!