首页 > 解决方案 > 用于从 HTTPS 网站下载文件的 Powershell 脚本

问题描述

我需要每天从日期过去的网站下载文件。我尝试使用以下代码 -

$url = "https://www.theocc.com/webapps/threshold-securities?reportDate=20190730"
$output = "C:\Users\Himanshu.Vats\Downloads\"
Invoke-WebRequest -Uri $url -OutFile $output

但它给出了错误 -

Invoke-WebRequest :底层连接已关闭:发送时发生意外错误。在 line:3 char:1 + Invoke-WebRequest -Uri $url -OutFile $output + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand

标签: powershell

解决方案


这是因为您的路径不是路径文件(您有一个 '\' 结束路径)

尝试这个:

$url = "https://www.theocc.com/webapps/threshold-securities?reportDate=20190730"
$output = "C:\Users\Himanshu.Vats\Downloads\result.csv"
Invoke-WebRequest -Uri $url -OutFile $output

推荐阅读