Powershell向下滚动网页/ Powershell屏幕截图 [英] Powershell Scroll down a webpage / Powershell Screenshot
问题描述
如何在powershell中打开网页并向下滚动。
实际上,我制作一个脚本,它会自己做一个网络报告,我想要。我可以打开网页,并用我的脚本开始测试,但我想让我的脚本向下滚动,以便可以采取正确的屏幕截图。请帮助。
准确地说,我希望我的脚本打开一个名为testmy.net的网站,并做一个网络报告。我想要的只是报告的截图,裁剪一切。我非常感谢任何帮助。
Q)如何在PS中向下滚动网页?我打开网站,我想向下滚动?
Q)如何截取特定内容的屏幕截图?
(经过一些研究,我得到了一些可以截取整个桌面的屏幕截图)
我附上了我需要的确切的屏幕截图。 p>
脚本从这里开始:
$ ie = new-object -comobject InternetExplorer.Application -property`
@ {navigate2 =http://testmy.net/SmarTest/combinedAuto; visible = $ true}
#等待页面完成加载
$ ie.fullscreen = $ true
do {sleep 5} until ($ not.Busy))
#获取ScreenShot(从Stackflow获取的脚本)
[Reflection.Assembly] :: LoadWithPartialName(System.Drawing)
函数截图([Drawing.Rectangle] $ bounds,$ path){
$ bmp = New-Object Drawing.Bitmap $ bounds.width,$ bounds.height
$ graphics = [Drawing.Graphics] :: FromImage($ bmp)
$ graphics.CopyFromScreen($ bounds.Location,[Drawing.Point] :: Empty,$ bounds.size)
$ bmp。保存($ path)
$ graphics.Dispose()
$ bmp.Dispose()
}
$ bounds = [Drawing.Rectangle] :: FromLTRB(0,0,1000,900)
截图$ boundsC:\screenshot.png
我想你正在寻找真的速度和肮脏。如果这是真的,并且您不介意丑陋,请尝试使用SendKeys 。 p>
$ ie = new-object -comobject InternetExplorer.Application -property`
@ {navigate2 =http:// testmy .net / SmarTest / combinedAuto; visible = $ true}
#等待页面完成加载
$ ie.fullscreen = $ true
do {sleep 5} until (-not($ ie.Busy))
[System.Windows.Forms.Cursor] :: Position = New-Object system.drawing.point(700,700)
[System.Windows
[Reflection.Assembly] :: LoadWithPartialName(System.Drawing)。 )
函数截图([Drawing.Rectangle] $ bounds,$ path){
$ bmp = New-Object Drawing.Bitmap $ bounds.width,$ bounds.height
$ graphics = Drawing.Graphics] :: FromImage($ bmp)
$ graphics.CopyFromScreen($ bounds.Location,[Drawing.Point] :: Empty,$ bounds.size)
$ bmp.Save($ path)
$ graphics.Dispose()
$ bmp.Dispose()
}
$ bounds = Drawing.Rectangle] :: FromLTRB(0,0,1000,900)
截图$ boundsC:\tmp\screenshot.png
继续用你发送的向下箭头的数量来解决问题,因此编辑 {DOWN 10}
。
害怕你会有足够的时间问题,你最终会回去使用另一个工具,但是。
请注意,我在测试期间更改了espn.com的网址。不知道发生了什么 - 你的速度测试?似乎要加载大约三个不同的网页。
How to open a webpage in powershell and scroll down.
Actually I am making a script which will do a network report on its own and give me a screenshot which I want. I can open the webpage and start the test with my script, but I want my script to scroll down so that the correct screenshot could be taken. Please Help.
To be precise, I want my script to open a website called testmy.net and do a network report. I want to take the screenshot of just the report and crop everything else. I would really appreciate any help.
Q) How do I scroll down a webpage in PS? I open the website and I want to scroll down?
Q) How do I take a screenshot of only a particular thing? (After some research I got some part which could take a screenshot of the whole desktop)
I have attached the screenshot of exact thing I need.
Script Starts Here:
$ie = new-object -comobject InternetExplorer.Application -property `
@{navigate2="http://testmy.net/SmarTest/combinedAuto"; visible = $true}
# Wait for the page to finish loading
$ie.fullscreen = $true
do {sleep 5} until (-not ($ie.Busy))
# Take A ScreenShot (Script taken from Stackflow)
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\screenshot.png"
I think you're looking for really quick and dirty. If that's true, and you don't mind ugly, try using SendKeys.
$ie = new-object -comobject InternetExplorer.Application -property `
@{navigate2="http://testmy.net/SmarTest/combinedAuto"; visible = $true}
# Wait for the page to finish loading
$ie.fullscreen = $true
do {sleep 5} until (-not ($ie.Busy))
[System.Windows.Forms.Cursor]::Position = New-Object system.drawing.point(700,700)
[System.Windows.Forms.SendKeys]::SendWait({DOWN 10})
# Take A ScreenShot (Script taken from Stackflow)
[Reflection.Assembly]::LoadWithPartialName("System.Drawing")
function screenshot([Drawing.Rectangle]$bounds, $path) {
$bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
$graphics = [Drawing.Graphics]::FromImage($bmp)
$graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
$bmp.Save($path)
$graphics.Dispose()
$bmp.Dispose()
}
$bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
screenshot $bounds "C:\tmp\screenshot.png"
Keep messing around with the number of down arrows you send until it's right -- so edit {DOWN 10}
.
Scared you're going to have enough timing issues that you eventually go back and use another tool, however. How many of these do you have to take?
Note that I did change the URL to espn.com while testing. Not sure what's going on at yours -- a speed test? Seemed to load about three different pages.
这篇关于Powershell向下滚动网页/ Powershell屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!