从网站ie.document方法Powershell的下载文件 [英] Powershell download file from website ie.document method

查看:450
本文介绍了从网站ie.document方法Powershell的下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用互联网探索11.我有一个手动鼠标点击下载文件,IE浏览器,但即时得到的提示保存打开的文件,我想能够绕过这一点,登录的到一个HTTPS网站小脚本由于我要去回地面运行呢?我失去了我的ie.navigate(URL)来只保存文件的最后一个参数?正如我在上面我使用IE11,这和降级声明是不是一种选择。

任何帮助将是巨大的。

  $用户名=获取内容-Path C:\\ username.txt
$密码=获取内容-Path C:\\的password.txt$即=新对象-ComObject internetExplorer.Application
$ ie.Visible = $假
$ ie.fullscreen = $假$ ie.Navigate(https://www.mft1.firstdataclients.com/cgi-bin/messageway/mwi.cgi)而($ ie.Busy -eq $真){启动睡眠-seconds 2}$ usernamefield = $ ie.Document.getElementByID(用户)
$ usernamefield.value = $用户名$ passwordfield = $ ie.Document.getElementByID('密码')
$ passwordfield.value = $密码$ ie.document.getElementById(请求)。点击()而($ ie.Busy -eq $真){启动睡眠-seconds 2}$ ie.Navigate(https://www.mft1.firstdataclients.com/cgi-bin/messageway/mwi.cgi?请求= ViewDownloaded)而($ ie.Busy -eq $真){启动睡眠-seconds 2}
$ ie.Document.getElementsByTagName('A')|其中,对象{$ _ HREF -match请求= TextDownload。} |其中,对象{$ _ HREF -matchCL9DFMDE'} |选择 - 第一1 -ExpandPropertyHREF$链接= $ ie.Document.getElementsByTagName('A')|其中,对象{$ _ HREF -match请求= TextDownload。} |其中,对象{$ _ HREF -matchCL9DFMDE'} |选择 - 第一1 -ExpandPropertyHREF$文件= $链接$文件名= [字符串]($文件).substring(122)$文件名$ ie.Navigate($文件)


解决方案

您可以使用调用-WebRequest的保存文档,就像这样:

 调用-的WebRequest -uriURL_OF_Download_file-OUTFILEsave_location

I have created a little script that log's on to a https website using Internet explore 11. I had a manual mouse click to Download file to IE but im getting the prompt to save open file I would like to be able to bypass this due to im going to run this in the back ground? Am I missing a param on the end of my ie.navigate(url) to just save the file? As I stated above I'm using IE11 for this and downgrading is not an option.

Any help would be great

$username= get-content -Path c:\username.txt
$password= get-content -Path c:\password.txt

$ie = New-Object -ComObject internetExplorer.Application
$ie.Visible= $false
$ie.fullscreen = $false

$ie.Navigate("https://www.mft1.firstdataclients.com/cgi-bin/messageway/mwi.cgi")

while ($ie.Busy -eq $true){Start-Sleep -seconds 2}  

$usernamefield = $ie.Document.getElementByID('user')
$usernamefield.value = $username

$passwordfield = $ie.Document.getElementByID('password')
$passwordfield.value = $password

$ie.document.getElementById("request").click()

while ($ie.Busy -eq $true){Start-Sleep -seconds 2}

$ie.Navigate("https://www.mft1.firstdataclients.com/cgi-bin/messageway/mwi.cgi?    request=ViewDownloaded")

while ($ie.Busy -eq $true){Start-Sleep -seconds 2}


$ie.Document.getElementsByTagName('a')| where-object {$_.href -match "request=TextDownload"} | where-object {$_.href -match 'CL9DFMDE'}| select -First 1 -ExpandProperty 'href'

$link=$ie.Document.getElementsByTagName('a')| where-object {$_.href -match "request=TextDownload"} | where-object {$_.href -match 'CL9DFMDE'}| select -First 1 -ExpandProperty 'href'

$file= $link 

$filename= [string]($file).substring(122)

$filename

$ie.Navigate("$file")

解决方案

You can use Invoke-WebRequest to save documents, like so:

Invoke-WebRequest -Uri "URL_OF_Download_file" -Outfile "save_location"

这篇关于从网站ie.document方法Powershell的下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆