-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetrates.ps1
More file actions
17 lines (13 loc) · 796 Bytes
/
getrates.ps1
File metadata and controls
17 lines (13 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$dateXPath = "//tr/td/a[@class='w']"
$rateXPath = "//tr/td/span[@class='w']/span[@class='nowrap'][2]"
$targetCurrency = "USD"
21..24 |% {
$url = "https://www.exchange-rates.org/exchange-rate-history/crc-usd-20$_"
#$url = "https://www.exchange-rates.org/exchange-rate-history/usd-crc-20$_"
$response = Invoke-WebRequest -Uri $url
$html = ConvertFrom-Html -Raw $response.Content
# Use the HtmlDocument object's SelectNodes method to run the XPath queries
$dateNodes = $html.DocumentNode.SelectNodes($dateXPath)
$rateNodes = $html.DocumentNode.SelectNodes($rateXPath)
0..($dateNodes.Count-1) | Select-Object @{Name="Date";Expression={[DateTime]$dateNodes[$_].InnerText.Trim()}},@{Name="Rate";Expression={[double]$rateNodes[$_].InnerText.Trim().Replace(" $targetCurrency","")}}
}