我的最终目标是使用PowerShell从一个网站下载一个zip文件,该网站首先需要通过初始页面登录。我发现的一个简单的powershell脚本示例如下:
# URL and Destination
$url = "https://example.com/reports/test.zip"
$dest = "c:\temp\testfiles"
# Define username and password
$username = 'User1'
$password = 'Password123'
# Convert to SecureString
$secPassword = ConvertTo-SecureString $password -AsPlainText -Force
# Create Credential Object
$credObject = New-Object System.Management.Automation.PSCredential ($username, $secPassword)
# Download file
Invoke-WebRequest -Uri $url -OutFile $dest -Credential $credObject
我主要关心的是我从我实际下载的zip文件中得到的html下载链接。链接如下:https://example.com/webclient/idownload(实际链接确实以/webclient/idownload结尾)。我还没有看到一个答案,什么是'idownload'扩展意味着在下载链接的类型方面。这是某种类型的安全下载链接,其中下载项目名称不像许多标准下载链接那样在html中:https://example.com/reports/test.zip.网页上有多个下载链接,我发现所有下载的html链接都是完全一样的,都以'idownload'结尾,尽管下载文件本身有不同的名称。总的来说,我希望深入了解我正在处理的这种类型的下载链接,以及如何使用PowerShell脚本有效地自动化下载过程。
1条答案
按热度按时间mspsb9vt1#
我有一个类似的案例,这对我很有效。请相应更新您的情况