Last active
September 3, 2024 12:39
-
-
Save ninmonkey/17f6a1f5b28249b6cb2ba8bc746ae4fb to your computer and use it in GitHub Desktop.
Combining a simple `CSS` / `XPath` query with regex works fairly well to find `icon` resources
This file contains hidden or 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
| #Requires -Module 'PSParseHtml' | |
| <# | |
| .Synopsis | |
| Combining a simple `CSS` / `XPath` query with regex works fairly well to find `icon` resources | |
| #> | |
| [Uri] $Url = 'https://na.alienwarearena.com' | |
| $xpath_doc ??= ConvertFrom-Html -Url $Url -Engine AgilityPack | |
| $css_doc ??= ConvertFrom-Html -Url $Url -Engine AngleSharp | |
| $Regex_IconNames = 'logo|favico|icon' | |
| $Found = [ordered]@{} | |
| $Found.Css = @( | |
| $css_doc.QuerySelectorAll('link[rel="icon"]') | |
| $css_doc.QuerySelectorAll('[href]') | |
| | ? Href -Match $Regex_IconNames | |
| ) | Sort-object OuterHtml -Unique | |
| $Found.XPath = @( | |
| $xpath_doc.SelectNodes('//*[@href]') | ?{ $_.Attributes['href'].Value -Match $Regex_IconNames } | |
| $xpath_doc.SelectNodes('//link[@rel="icon"]') | |
| ) | Sort-object OuterHtml -Unique | |
| $found.XPath | ft -Auto OriginalName, OuterHtml, XPath | |
| $found.Css | ft -Auto LocalName, ClassName, Href, *attr*, *OuterHtml | |
| @( $Found.css.outerhtml; $found.xpath.outerhtml ) | Sort-object -Unique | |
| <# output | |
| <link rel="apple-touch-icon" href="https://media.alienwarearena.com/images/favicons/apple-touch-icon.png" sizes="180x180"> | |
| <link rel="icon" href="https://media.alienwarearena.com/images/favicons/favicon-16x16.png" sizes="16x16" type="image/png"> | |
| <link rel="icon" href="https://media.alienwarearena.com/images/favicons/favicon-32x32.png" sizes="32x32" type="image/png"> | |
| <link rel="icon" href="https://media.alienwarearena.com/images/favicons/favicon.ico"> | |
| <link rel="manifest" href="https://media.alienwarearena.com/images/favicons/manifest.json"> | |
| <link rel="mask-icon" href="https://media.alienwarearena.com/images/favicons/safari-pinned-tab.svg" color="#712cf9"> | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment