Last active
August 23, 2019 22:24
-
-
Save markwragg/b24e11583b18c5ca35233a20a6ab4ad2 to your computer and use it in GitHub Desktop.
Top 100 scrape from Rotten Tomatoes with rating
This file contains 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-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