PowerShell でブラウザのスクリーンキャプチャをとる [PowerShell]
IE でウェブサイトを開いてそのスクリーンショットを撮るスクリプトを書いてみた。
Param([String]$url, [String]$filename, [String]$format="png")
if (!$url -or !$filename) { return }
$ie = new-object -com InternetExplorer.Application
# URL を開く
$ie.Navigate($url)
# ページをロードし終わるまで待つ
while ($ie.Busy) {sleep -milliseconds 10}
# バー関連はすべて消して IE を可視化
$ie.StatusBar = $false
$ie.ToolBar = $false
$ie.MenuBar = $false
$ie.AddressBar = $false
$ie.Visible = $true
# IE のウィンドウを前面に持ってくる
$wsh = new-object -com WScript.Shell
$wsh.AppActivate("Explorer")
# スクリーンキャプチャ
$bitmap = new-object Drawing.Bitmap($ie.Width, $ie.Height)
$graphics = [Drawing.Graphics]::FromImage($bitmap)
$graphics.CopyFromScreen($ie.Left, $ie.Top, 0, 0, $bitmap.Size)
$bitmap.Save($filename, $format)
$ie.Quit()
これを cap.ps1 のような名前で保存して以下のように使う。
PS G:\> .\cap.ps1 http://www.yahoo.co.jp/ test.gif gif
画面サイズを調整したい場合は $ie.Width と $ie.Height に値を代入してあげれば良いと思う。
コメント 0