【发布时间】:2016-03-09 19:38:09
【问题描述】:
我正在尝试下载文件,但没有看到 Internet Explorer 的打开/保存对话框。登录表单比发送 Web 请求复杂得多,因此我仅限于使用 InternetExplorer.Application。
$credentials = Get-Credential -Message "Enter the username and password..."
$username = $credentials.UserName
$password = $credentials.GetNetworkCredential().password
$ie = New-Object -com InternetExplorer.Application
$ie.navigate("https://example.com/getFile?downloadId=123")
$ie.document.getElementById("username").value= "$username"
$ie.document.getElementById("password").value = "$password"
$ie.document.getElementById("fm1").submit()
在执行上述代码时,登录工作完美,下载正在启动,但我看到一个像下面这样的窗口,这是我想要抑制的。虽然我知道最终用户可以更改此设置,但任何通过 powershell 自动下载的建议都会很好。
上面是一个示例窗口。
【问题讨论】:
-
现代 IE 版本 (10/11) 似乎没有简单的方法可以做到这一点。看这篇文章和cmets:Internet Explorer: Disable "Do you want to open or save this file?" download prompt.
标签: .net windows powershell com web-scraping