Skip to content

Instantly share code, notes, and snippets.

@markwragg
Last active August 23, 2019 22:24
Show Gist options
  • Save markwragg/b24e11583b18c5ca35233a20a6ab4ad2 to your computer and use it in GitHub Desktop.
Save markwragg/b24e11583b18c5ca35233a20a6ab4ad2 to your computer and use it in GitHub Desktop.
Top 100 scrape from Rotten Tomatoes with rating
Function Get-Top100Movies {
[cmdletbinding()]
Param(
[Int[]]$Year = ((Get-Date).Year -1)
)
foreach ($Yr in $Year) {
$Result = (Invoke-WebRequest "https://www.rottentomatoes.com/top/bestofrt/?year=$Yr") -split '</tr>'
$Result | Select -Skip 1 | ForEach-Object {
$_ -match '(?smi)<td>\s*?<a href="/m/.*?>\s*(.*?)</a>.*?</td>' | Out-Null
if ($matches) { $Movie = $matches[1] }
$_ -match '\d+(?=%)' | Out-Null
if ($matches) { $Rating = $matches[0] } else { $Rating = $null }
if ($movie) {
[pscustomobject]@{
Movie = $Movie
Rating = [int]$Rating
}
}
}
}
}
Get-Top100Movies -Year (2010..2017) | Sort Rating -Descending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment