从WebPage获取特定标签

时间:2017-11-28 22:48:12

标签: html powershell

我一直在努力使用PowerShell(以及众多StackOverflow线程/ Google文章) - 但未能使其发挥作用。

我有这个PowerShell脚本:

$URI = "http://example.html"
$HTML = Invoke-WebRequest -Uri $URI

返回下面的HTML。 我只是试图获得“In”和“Out”值,这些值显示在“{per {{}}每周{值的平均最长5分钟值”下,这些值具有几乎相同的标记。

Daily' Graph (5 Minute interval): - and not the

1 个答案:

答案 0 :(得分:1)

您可以使用-match比较运算符。 -match将仅匹配第一次出现,并且由于值是HTML输出中的第一个值,因此它将为您提供所需的值。 你可以这样做:

$regexes = @('<span class="in">In<\/span> (.*)/', '<span class="out">Out</span> (.*)')

$regexes | ForEach-Object {
    $htmlText -match $_ 
    $Matches[1]
}
相关问题