powershell - PowerShell 在 html 站点下载最新文件
问题描述
我试图让 PowerShell 从http://download.affixa.com/MSI/versions.html下载最新的 msi 文件,但我永远找不到该文件。不过,我可以让它从不同的站点下载文件。当我尝试从该站点获取信息时,只有当我在他们的页面上看不到任何 Google 时才会显示 Google 信息。此外,如果我还没有文件(与脚本在同一目录中),我只想下载该文件,因为我什至无法让它工作,所以我还没有想出来。
$site = (Invoke-WebRequest -URI "http://download.affixa.com/MSI").Links | Where-Object {$_.href -like ‘*msi*’} | Select-Object href
Invoke-WebRequest -URI $site -Outfile "$PSScriptRoot\Affixa.msi"
解决方案
正如李提到的,您需要使用浏览器/解析器,因为页面内容是在页面加载时加载的。
这对我有用(据我所知,IE 在 Windows 10 上仍然可用)。
# reset '$lastLink'
$lastLink = $null
while($null -eq $lastLink) {
# set the url we want to parse
$url = 'http://download.affixa.com/MSI/versions.html'
# create an Internet Explorer object
$ie = New-Object -com internetexplorer.application;
# hide the Internet Explorer Application
$ie.visible = $false;
# navigate to the url specified
$ie.navigate($url);
# wait for the application beeing ready to use
while($ie.Busy -eq $true) {
Start-Sleep -Seconds 1
}
Start-Sleep -Seconds 2
# select the last link of the page which matches the pattern
$lastLink = $ie.Document.getElementsByTagName('a') | Select-Object -Last 1 | Select-Object -ExpandProperty href
# close the Internet Explorer application
$ie.quit()
}
# download the msi
Invoke-WebRequest -Uri $lastLink -OutFile "$PSScriptRoot\Affixa.msi"
推荐阅读
- c - OpenSSL DTLS 连接永远不会建立
- javascript - 使用不同的类方法,取决于使用的目标编译器选项
- python-3.x - 出错整数或布尔数组是有效索引
- wordpress - 如何将会员卡添加到我的网站,可以会员下载
- php - 使用 FastCGI 在 IIS 上配置 PHP 以显示警告但继续执行
- java - 我想将某些列的边框设置为粗,但所有列都已设置
- optaplanner - OptaPlanner VRPTW - ArrivalTimeUpdatingVariableListener 的异常在 FULL_ASSERT 但不是在生产模式
- javascript - 如何使用 redux 制作切换器来翻译网站
- c - while 循环无法检测到简单的数学运算
- javascript - 我的页面在 ios 中加载一半但在 android 中加载