1
1

More than 3 years have passed since last update.

PowerShellでIE画面の内容を出力する

Posted at

背景

PowerShell課題を解いていきます。

課題

PowerShellでIE画面の内容を出力する。

IEを立ち上げ、任意のページを開く

$ie = New-Object -ComObject InternetExplorer.Application #IE起動        
$ie.Navigate("https://www.google.com")                   #URL指定
$ie.Visible = $true                                      #表示
While($ie.Busy)                                          #読み込みが終わるまで待機
{Start-Sleep -Seconds 1 }
$doc = $ie.Document                                      #画面情報取得

PowerShellでIEの内容(テキストやボタンの文字)を取得する

$btntxt = $doc.getElementsByName("btnK")                 #ボタン文字の取得

取得した内容を、PowerShellコンソールに出力する

Write-Host $btntxt[0].value -ForegroundColor Green

実行結果

キャプチャ.PNG

まとめ

実行できたけど、たまにエラーになるときがあります。
なぜだろう。
改善したほうがいいポイントなどあればご指摘ください。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1