Created
May 13, 2023 15:51
-
-
Save lidopaglia/5d81b5b49baab62bed05bb4f756de9bf to your computer and use it in GitHub Desktop.
Example using PowerHTML module to parse html table content
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
#!/usr/bin/env pwsh | |
# Requires -Module PowerHTML | |
# Most downloaded movies via torrent sites by TorrentFreak.com | |
param( | |
[parameter()] | |
[switch]$full=$false | |
) | |
function tfdl { | |
try { | |
$Url = 'https://torrentfreak.com/top-10-most-torrented-pirated-movies/' | |
$Req = Invoke-Webrequest -Uri $Url -ErrorAction Stop | |
} catch { | |
throw $error[0] | |
} | |
$htmlDom = $Req.Content | ConvertFrom-Html | |
$table = $htmlDom.SelectNodes('//table') | |
foreach ($row in $table.SelectNodes('tr')) { | |
$rank=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[1]').InnerText.Trim()) | |
$last=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[2]').Innertext.Trim()) | |
$name=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[3]').Innertext.Trim()) | |
$rate=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[4]').ChildNodes[0].Innertext.Trim()) | |
$imdb=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[4]').ChildNodes[0].Attributes.Value) | |
$trlr=[System.Web.HttpUtility]::HtmlDecode( | |
$row.SelectSingleNode('td[4]').ChildNodes[2].Attributes.Value) | |
[PSCustomObject]@{ | |
Rank = $rank | |
Last = $last | |
Name = $name | |
Rating = $rate | |
IMDb = $imdb | |
Trailer = $trlr.split("&")[0] | |
} | |
} | |
} | |
switch($full) { | |
$true { | |
tfdl | format-table -autosize | |
} | |
default { | |
tfdl | select-object Rank,Last,Name,Rating | format-table -autosize | |
} | |
} |
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
$ ./tfdl.ps1 | |
Rank Last Name Rating | |
---- ---- ---- ------ | |
1 (…) Dungeons & Dragons: Honor Among Thieves 7.4 | |
2 (…) Renfield 6.4 | |
3 (…) The Pope’s Exorcist 6.1 | |
4 (3) Avatar: The Way of Water 7.8 | |
5 (1) Ant-Man and the Wasp: Quantumania 6.4 | |
6 (2) Scream VI 6.8 | |
7 (6) Shazam! Fury of the Gods 6.3 | |
8 (8) John Wick: Chapter 4 8.5 | |
9 (4) Ghosted 5.8 | |
10 (…) Mafia Mamma 5.3 | |
$ ./tfdl.ps1 -full | |
Rank Last Name Rating IMDb Trailer | |
---- ---- ---- ------ ---- ------- | |
1 (…) Dungeons & Dragons: Honor Among Thieves 7.4 https://www.imdb.com/title/tt2906216/ https://www.youtube.com/watch?v=IiMinixSXII | |
2 (…) Renfield 6.4 https://www.imdb.com/title/tt11358390/ https://www.youtube.com/watch?v=6LmO6rmDW08 | |
3 (…) The Pope’s Exorcist 6.1 https://www.imdb.com/title/tt13375076/ https://www.youtube.com/watch?v=YJXqvnT_rsk | |
4 (3) Avatar: The Way of Water 7.8 https://www.imdb.com/title/tt1630029/ https://www.youtube.com/watch?v=o5F8MOz_IDw | |
5 (1) Ant-Man and the Wasp: Quantumania 6.4 https://www.imdb.com/title/tt10954600/ https://www.youtube.com/watch?v=ZlNFpri-Y40 | |
6 (2) Scream VI 6.8 https://www.imdb.com/title/tt17663992/ https://www.youtube.com/watch?v=h74AXqw4Opc | |
7 (6) Shazam! Fury of the Gods 6.3 https://www.imdb.com/title/tt10151854/ https://www.youtube.com/watch?v=Zi88i4CpHe4 | |
8 (8) John Wick: Chapter 4 8.5 https://www.imdb.com/title/tt10366206/ https://www.youtube.com/watch?v=yjRHZEUamCc | |
9 (4) Ghosted 5.8 https://www.imdb.com/title/tt15326988/ https://www.youtube.com/watch?v=IAdCsNtEuBU | |
10 (…) Mafia Mamma 5.3 https://www.imdb.com/title/tt13923456/ https://www.youtube.com/watch?v=a29h1P66uXc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment