如何使用 PowerShell 获得 HTML 评论

How to get an HTML comment with PowerShell

如果我在HTML中发表评论:

<html>
    <body>

      <!-- some comment1 -->  

    </body>
</html>
<!-- some comment2 -->  

如何使用 PowerShell 获取它?

我试着在一些网站上测试它:

所以我用了:

$url = "https://www.w3schools.com/tags/tag_comment.asp" 
$webrequest = Invoke-WebRequest -Uri $url 
$webrequest.ParsedHtml.body.innerHTML

但是$webrequest.ParsedHtml.body.innerHTML是一个字符串,我不知道如何获取评论或者只是列出网站上的所有评论。

我不确定是否要获取 [if IE] 类型的评论,因为它们是特殊符号(即不 只是 评论)。

但是,要获取其他内容,您可以在 tagName

上进行过滤
$url = "https://www.w3schools.com/tags/tag_comment.asp" 
$webrequest = Invoke-WebRequest -Uri $url
$webrequest.AllElements | Where-Object tagName -eq "!"

结果:

innerHTML : 
innerText : 
outerHTML : 
outerText : 
tagName   : !

innerHTML : <!-- MainLeaderboard-->
innerText : 
outerHTML : <!-- MainLeaderboard-->
outerText : 
tagName   : !

innerHTML : <!-- BottomMediumRectangle -->
innerText : 
outerHTML : <!-- BottomMediumRectangle -->
outerText : 
tagName   : !

innerHTML : <!-- RightBottomMediumRectangle -->
innerText : 
outerHTML : <!-- RightBottomMediumRectangle -->
outerText : 
tagName   : !