使用 Powershell 仅查找今天发生的全球假日



我是使用Powershell的新手,我正在尝试使用下面的网站抓取一个网站以仅查找今天发生的全球假期。

https://eresearch.fidelity.com/eresearch/markets_sectors/global/holidayCalendar.jhtml

这是我到目前为止得到的,任何帮助将不胜感激!

$a = Get-Date -UFormat "%m/%d/%y" #to get the date in mm/dd/yy format
$source = "https://eresearch.fidelity.com/eresearch/markets_sectors/global/holidayCalendar.jhtml"
$result = Invoke-WebRequest $source
$d = $result.AllElements | Where Class -eq "layout-calendar-content-column" | Select -ExpandProperty innerText 
echo $d

理想情况下,它只会显示与变量$a中包含的日期匹配的假期。

您的脚本几乎完成。 而不是你的echo语句,试试这个:

$d -split "`n" | ? { $_ -like "*$a*" }

更新:针对您的用例

($d | Out-String) -split "`n" | Where-Object { $_ -like "*$a*" }

最新更新