我的要求是在Internet Explorer中截取整页的屏幕截图。我知道网上有不同的工具可以做同样的事情,但由于我想在没有管理员权限的系统上实现这一点,我只能用一些不需要任何安装的程序来实现。 我正在寻找一个程序,它可以接受来自excel的输入(站点URL),然后获取这些站点的整页屏幕截图。 直到现在我才设法在IE中打开一个网站,然后做F11以最大化屏幕并截取它的截图。但是,由于页面高度更高,因此会产生裁剪页面捕捉。我用PowerShell尝试过这个。 有什么建议/想法吗?
Capturing a screenshot
Param(
#[Parameter(Mandatory = $true)][string]
$Path = "C:\Sagar\Screens"
)
$FileName = "$env:COMPUTERNAME - $(get-date -f yyyy-MM-dd_HHmmss).bmp"
$File = "$Path\$FileName"
Add-Type -AssemblyName System.Windows.Forms
Add-type -AssemblyName System.Drawing
# Gather Screen resolution information
$Screen = [System.Windows.Forms.SystemInformation]::VirtualScreen
$Width = $Screen.Width
$Height = $Screen.Height
$Left = $Screen.Left
$Top = $Screen.Top
$ie = New-Object -com internetexplorer.application
$ie.Visible = $true
$ie.Navigate2("https://www.google.com/webhp?sourceid=chrome- instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20send%20keys%20through%20powershell")
while($ie.busy){
Sleep -Seconds 2
}
Sleep -Seconds 2
$sig = '[DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow);'
Add-Type -MemberDefinition $sig -name NativeMethods -namespace Win32
# Minimize window
[Win32.NativeMethods]::ShowWindowAsync($ie.HWND, 2)
# Restore window
[Win32.NativeMethods]::ShowWindowAsync($ie.HWND, 3)
#$ie.FullScreen = $true
Sleep -seconds 3
[void] [System.Reflection.Assembly]::LoadWithPartialName("'System.Windows.Forms")
[System.Windows.Forms.SendKeys]::SendWait("{F11}")
sleep -Seconds 2
Add-Type -AssemblyName System.Drawing
# Create bitmap using the top-left and bottom-right bounds
$bitmap = New-Object -TypeName System.Drawing.Bitmap -ArgumentList $ie.Width, $ie.Height
# Create Graphics object
$graphic = [System.Drawing.Graphics]::FromImage($bitmap)
$ie.Left
$ie.Top
# Capture screen
$graphic.CopyFromScreen($ie.Left, $ie.Top, 0, 0, $bitmap.Size)
# Save to file
$bitmap.Save($File)
Write-Output "Screenshot saved to:"
Write-Output $File
#
找到了解决方案。有一种叫做Watin'这有助于使用IE和Firefox进行自动化。它有一种捕获整页截图的方法。虽然截图质量是平均值,但Watin效果很好。
$executingScriptDirectory = Split-Path -Path $MyInvocation.MyCommand.Definition -Parent
$filePath = $executingScriptDirectory + "\WatiN-2.1.0.1196\bin\net40\WatiN.Core.dll" #$executingScriptDirectory + "\net20\WatiN.Core.dll"
$filePath1 = $executingScriptDirectory + "\WatiN-2.1.0.1196\bin\net40\Interop.SHDocVw.dll"
[System.Reflection.Assembly]::LoadFile($filePath);
[System.Reflection.Assembly]::LoadFile($filePath1);
$url = "https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=how%20to%20send%20keys%20through%20powershell"
$ie = new-object WatiN.Core.IE $URL
while($ie.busy){
sleep -milliseconds 50
}
$ie.BringToFront()
$ie.CaptureWebPageToFile("C:\Sagar\Scripts\IsIt.jpg");