Powershell 如何通过简单的程序截取整个页面的截图?

Powershell 如何通过简单的程序截取整个页面的截图?,powershell,internet-explorer-9,ui-automation,screen-capture,browser-automation,Powershell,Internet Explorer 9,Ui Automation,Screen Capture,Browser Automation,我的要求是在Internet Explorer中截取整个页面的屏幕截图。我知道网上有不同的工具可以做同样的事情,但因为我想在我没有管理员权限的系统上实现这一点,我只能用一些不需要任何安装的程序来实现。 我正在寻找一个程序,可以接受输入(网站网址)从excel,然后采取这些网站的全页屏幕截图。 到目前为止,我只在IE中打开了一个站点,然后使用F11最大化屏幕并截图。但是,由于页面高度更高,因此会出现裁剪页面快照。我用PowerShell试过了。 有什么建议/想法吗 Capturing a scre

我的要求是在Internet Explorer中截取整个页面的屏幕截图。我知道网上有不同的工具可以做同样的事情,但因为我想在我没有管理员权限的系统上实现这一点,我只能用一些不需要任何安装的程序来实现。 我正在寻找一个程序,可以接受输入(网站网址)从excel,然后采取这些网站的全页屏幕截图。 到目前为止,我只在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");

我不确定哪个部分需要更多信息。您是否要求我们修复您没有向我们显示的PowerShell脚本(请先向我们显示代码)?你是否要求一个能满足你要求的程序(离题)?你真的需要屏幕截图吗?不是只有一些部分你可以从网页上刮下来吗?对不起,Matt,我是StackOverflow的新手,我还在学习如何使用它。已经添加了我到现在为止所做的代码:)我正在尝试通过Powershell实现全页面屏幕捕获。但是经过大量的研发,我想用PS可能很难做到。所以,如果你能在Powershell或其他程序上帮助我,我什么都可以。我只想要整页的屏幕截图。没问题。感谢您添加代码,因为现在这个问题可以看得更容易,因为我们有一些工作了。但是屏幕截图的动机是什么?您是否可以将页面打印到文件?取决于页面,因为这可能会扭曲页面。如果网页需要滚动怎么办?此代码为我提供了页面上可见内容的屏幕截图。但是页面下方的不可见区域没有被捕获。这就是我的目标。页面的可见+不可见区域并创建其图像。找到了解决方案。有一种叫做“Watin”的东西,它有助于使用IE和Firefox实现自动化。它有一种捕获整页屏幕截图的方法。虽然截图质量一般,但Watin的作品却完美无瑕。请让我知道,如果你能使图像质量更好。