forked from brianary/scripts
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathGet-Html.ps1
42 lines (34 loc) · 1.17 KB
/
Get-Html.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<#
.SYNOPSIS
Gets elements from a web response by tag name.
.INPUTS
Microsoft.PowerShell.Commands.HtmlWebResponseObject to parse elements from.
.OUTPUTS
System.__ComObject containing the parsed element COM object.
.LINK
Invoke-WebRequest
.EXAMPLE
Invoke-WebRequest https://www.h2g2.com/ -UseBasicParsing:$false |Get-Html.ps1 title |select text
text
----
h2g2 - The Guide to Life, The Universe and Everything
.EXAMPLE
Invoke-WebRequest https://http.cat/ -UseBasicParsing:$false |Get-Html.ps1 script |measure |select Count
Count
-----
5
#>
[CmdletBinding()][OutputType([__ComObject])] Param(
# The name of elements to return all occurrences of.
[Parameter(Position=0,Mandatory=$true)][Alias('ElementName')][string]$TagName,
# The Invoke-WebRequest output to parse.
[Parameter(Position=1,ValueFromPipeline=$true)]
[Microsoft.PowerShell.Commands.HtmlWebResponseObject]$Response
)
Process
{
if(!$Response.ParsedHtml)
{throw "$($MyInvocation.MyCommand.Name) requires -UseBasicParsing input to be false."}
Write-Verbose "Reading $TagName elements from '$($response.ParsedHtml.title)'"
$response.ParsedHtml.getElementsByTagName($TagName)
}