我正在尝试使用脚本下载所有金县excel文件的按日期总计计数,该脚本稍后将在使用任务管理器时运行。由于该链接不是静态链接,因此我陷入了困境,其命名约定很可能在未来几个月内发生变化。
这是我到目前为止编写的代码:
@echo off
::Script to download COVID-19 Data
echo "Downloading Total counts by date for all King County"
powershell -Command "Invoke-WebRequest https://www.kingcounty.gov/depts/health/covid-19/data/~/media/depts/health/communicable-diseases/documents/C19/data/covid-data-daily-counts-sept-14.ashx -Outfile CovidData.xlsx
echo "Download has been successful!"
cls
pause
我想知道是否有一种方法可以在invoke-webrequest中添加诸如“ *”之类的通配符,以忽略链接的“ sept-14”部分。
链接:https://www.kingcounty.gov/depts/health/covid-19/data/daily-summary.aspx
需要脚本自动与任务管理器链接的链接(所有金县的按日期总计):https : //www.kingcounty.gov/depts/health/covid-19/data/~/media/depts/health/传染病/文档/C19/data/covid-data-daily-counts-sept-14.ashx
我使用Windows Powershell ISE在我这边创建并测试了Powershell脚本,它能以5/5的速度工作,希望对您也有用!
$start_time = Get-Date
$url = "https://www.kingcounty.gov/depts/health/covid-19/data/daily-summary.aspx"
$xlFile = "E:\Test\CovidData.xlsx"
$http_request = New-Object -ComObject Microsoft.XMLHTTP
$http_request.open('GET', $url, $false)
#Sending the request
$http_request.send()
$Contents = $http_request.ResponseText
$pattern = "([\w\-\.,@?^=%&/~\+#]*[\w\-\@?^=%&/~\+#])(\.ashx)"
$Links = $Contents | Select-String $pattern -AllMatches | ForEach-Object {$_.Matches.Value} | sort -unique
$Filter = $Links -match "data-daily"
$MyUrlFile = "https://www.kingcounty.gov/depts/health/covid-19/data/" + $Filter
$MyUrlFile
Invoke-WebRequest "$MyUrlFile" -Outfile $xlFile
if (Test-Path $xlFile) { Start $xlFile }
Write-Output "Running Script Time taken is : $((Get-Date).Subtract($start_time).Seconds) second(s)"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句