Powershell:下载或保存整个ie页面的源代码 [英] Powershell: Download or Save source code for whole ie page
问题描述
我有这个PS脚本,它登录到一个网站,然后导航到另一个页面。
I have this PS script it logins to a site and then it navigate's to another page.
我想保存该页面的整个源代码。但由于某种原因。
I want to save whole source for that page. but for some reason. some parts of source code is not coming across.
$username = "myuser"
$password = "mypass"
$ie = New-Object -com InternetExplorer.Application
$ie.visible=$true
$ie.navigate("http://www.example.com/login.shtml")
while($ie.ReadyState -ne 4) {start-sleep -m 100}
$ie.document.getElementById("username").value = "$username"
$ie.document.getElementById("pass").value = "$password"
$ie.document.getElementById("frmLogin").submit()
start-sleep 5
$ie.navigate("http://www.example.com/thislink.shtml")
$ie.Document.body.outerHTML | Out-File -FilePath c:\sourcecode.txt
这里是代码的pastebin不会遇到
http://pastebin.com/Kcnht6Ry
Here is pastebin of code which is not coming across
http://pastebin.com/Kcnht6Ry
推荐答案
在您导航之后,再次检查Ready状态,而不是使用睡眠状态。
After you navigate, check for the Ready State again instead of using a sleep. The same code that you had will work.
在运行代码之后,如果站点加载缓慢,睡眠时间可能不够长。
It appears after running the code, the sleep may not be long enough if the site is slow to load.
while($ie.ReadyState -ne 4) {start-sleep -m 100}
看起来还有另外一篇关于这个
innerHTML将CDATA转换为注释它看起来像是某个人在该页面上创建了一个可以清理它的功能。这将是这样的,一旦你有你的代码中声明的函数
It also looks like there is another post regarding this innerHTML converts CDATA to comments It looks like some one created a function on that page where you can clean it up. It would be something like this once you have the function declared in your code
htmlWithCDATASectionsToHtmlWithout($ie.Document.body.outerHTML) | Out-File -FilePath c:\sourcecode.txt
这篇关于Powershell:下载或保存整个ie页面的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!