Skip to content

Commit 0153f95

Browse files
authored
📄 ConvertFrom-HTML (#5)
1 parent 52dba0f commit 0153f95

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

Public/ConvertFrom-HTML.ps1

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,47 @@
44
.DESCRIPTION
55
Long description
66
.EXAMPLE
7-
PS C:\> <example usage>
8-
Explanation of what the example does
7+
PS C:\> $HTMLString = @"
8+
<!DOCTYPE html>
9+
<html>
10+
<body>
11+
<h1>My First Heading</h1>
12+
<p>My first paragraph.</p>d
13+
</body>
14+
</html>
15+
"@
16+
PS C:\> $HTMLString | ConvertFrom-HTML -OutVariable result
17+
18+
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
19+
-------- ---- -------------- -------------- ------------- ---------
20+
Document #document 0 4 103 …
21+
22+
PS C:\> $result.SelectSingleNode("//body/h1")
23+
24+
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
25+
-------- ---- -------------- -------------- ------------- ---------
26+
Element h1 0 1 16 My First Heading
27+
28+
Convert HTML string to a HtmlNode via the pipeline.
29+
30+
.EXAMPLE
31+
PS C:\> $uri = "https://www.powershellgallery.com/"
32+
PS C:\> $result = ConvertFrom-HTML -uri $uri
33+
PS C:\> $result
34+
35+
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
36+
-------- ---- -------------- -------------- ------------- ---------
37+
Document #document 0 4 17550 …
38+
39+
Fetch and parse $uri directly via the URI pipeline.
40+
.EXAMPLE
41+
PS C:\> Get-Item $testFilePath | ConvertFrom-Html
42+
43+
NodeType Name AttributeCount ChildNodeCount ContentLength InnerText
44+
-------- ---- -------------- -------------- ------------- ---------
45+
Document #document 0 5 105 …
46+
47+
Parse an HTML file piped from Get-Item.
948
.INPUTS
1049
[String[]]
1150
[System.IO.FileInfo[]]

0 commit comments

Comments
 (0)