正如标题所述,我想从互联网上下载一个文件,特别是在这网页上下载。我已经研究了如何使用Invoke-WebRequest
、curl
和certutil
。所有这些选项都下载站点的HTML。下载的特定URL如下所示:https://bluetoothinstaller.com/bluetooth-command-line-tools/BluetoothCLTools-1.2.0.56.exe
。
调用类似于以下内容的内容只需下载HTML:
Invoke-WebRequest -Uri 'https://bluetoothinstaller.com/bluetooth-command-line-tools/BluetoothCLTools-1.2.0.56.exe' -OutFile 'test.exe'
或者,如果有人知道如何通过HTML下载链接,请分享。
如果解决方案不需要任何额外的软件,而是灵活的话,我更愿意这样做。
谢谢!
发布于 2022-02-09 04:04:24
看看去年年底时我写的一些代码,我发现了这一行:
(New-Object System.Net.WebClient).DownloadFile($URL, $ZipFile)
在我的例子中,我试图下载最新的SQLite,它成功了。在您的示例中,您可能希望将$ZipFile变量重命名为类似于$ExeFile的内容。
构建文件路径/名称并定义文件保存位置的命令如下:
$ZipFile = "$PSScriptRoot\$(Split-Path -Path $URL -Leaf)"
至于从网页中提取文件的下载路径,我还没有这样做。这是一件有目标的事情,但我还需要一段时间才能找到答案。
发布于 2022-02-09 04:47:57
下面对我有用,请注意OutFile
的评论。您可能会在浏览器的开发工具的“网络”选项卡上找到有用的东西。
$params = @{
UseBasicParsing = $true
Uri = "https://bluetoothinstaller.com/bluetooth-command-line-tools/BluetoothCLTools-1.2.0.56.exe"
Headers = @{
Referer = "https://bluetoothinstaller.com/bluetooth-command-line-tools/download.html"
}
OutFile = 'path/to/download.exe' # Change this
}
Invoke-RestMethod @params
https://stackoverflow.com/questions/71043712
复制相似问题