regex - powershell WebClient 为 zip 文件解析链接或正则表达式
问题描述
我有一个几乎可以工作的脚本,但我需要在 URL 上添加解析或通配符,因为 URL 将更改为我每个月都不知道的字符。我必须使用 New-Object System.Net.WebClient 因为调用 Web 请求被阻止。所以,我在想是否有人知道如何使用我知道的字符下载链接并剥离链接的其余部分。
以下链接示例
Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip
Full-CSV-data-file-Dec18-ZIP-3427K.zip
Full-CSV-data-file-Nov18-ZIP-3543K-21860.zip
所以在上面的链接中,我知道最新的文件将包含 Jan19,它是一个 zip 文件。我正在使用的脚本是
$currentMonthNo = get-date -format "MM"
$currentMonthName = (get-date((get-date).addmonths(-2)) -format MMM)
$currentYearNo = get-date –format yy
$url = "http://www.website.com/Full-CSV-data-file-$currentMonthName$currentYearNo-ZIP-3633K-53821.zip"
$output = "C:\Folder\Full-CSV-data-file-Jan19-ZIP-3633K-53821.zip"
$start_time = Get-Date
$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
#OR
(New-Object System.Net.WebClient).DownloadFile($url, $output)
Write-Output "Time taken: $((Get-Date).Subtract($start_time).Seconds) second(s)"
Write-Output $url
Start-Sleep -s 6
解决方案
推荐阅读
- visual-c++ - 函数返回错误的浮点值。我该如何解决?
- google-sheets - 您如何使用日期范围进行查询?
- c - NetworkByteOrder 是否与 Big endian 相同?
- java - 当控制器的返回类型为接口的 Mono 时,返回值不会将返回值转换为 json,在 webflux 中
- perl - 下面的代码会不会有任何字符串注入
- angular - 通过搜索栏从 Firestore 查询数据
- jquery - 我想用最少的功能调用多个弹出窗口
- javascript - 是否有其他方法可以使用 Jquery 删除父表行和子表行
- c++ - 按标签分隔输入
- ssl - 如何使用自签名证书嗅探从客户端到某个网站的加密流量?