Powershell Invoke-WebRequest - 收集指定数据

Powershell Invoke-WebRequest - Gather specified data

我正在尝试从打印机的网页收集 Total Pages Printed。该脚本可以...

  1. 加载登录页面。
  2. 导航到维护子页面
  3. Select 包含所需数据的列

但是,我不知道如何调整脚本以仅捕获我需要的数字。

$R=Invoke-WebRequest http://1.2.3.4/status.html -SessionVariable session1

#B553 - name w Html
$R.Forms[0].Fields["B553"]="login"
$R.Forms[0].Fields["password"]="password"

$Invoke1=Invoke-WebRequest -Uri ("http://1.2.3.4/status.html" + $R.Forms[0].Action) -WebSession $session1 -Method POST -Body $R.Forms[0].Fields

Start-Sleep -s 5

$Invoke2=Invoke-WebRequest 'http://1.2.3.4/Maintance-sub-page' -WebSession $session1

$Invoke2.AllElements | where tagname -EQ "dd" | Select innerText

以下结果:

$Invoke2.AllElements | where tagname -EQ "dd" | Select innerText

Total Pages in web-page

Total pages result in PS

HTML

看起来 Powershell 中的结果与 HTML 页面上的结果顺序相同。看起来这些结果是一个数组,而且(如果我算对了),你想要的字段看起来是 23(数组从 0 开始)。

试试下面的方法...

$($Invoke2.AllElements | where tagname -EQ "dd" | Select innerText)[23]