货币换算器 - Google 财经

货币换算器 - Google 财经

https://finance.google.cn/finance/converter

Google 提供的货币汇率在线转换工具。可以在中国使用(google.cn)。如果当作 API 使用,由于存在跨域问题,只能用于后端(或浏览器扩展)。

API

https://finance.google.cn/finance/converter?a=100&from=JPY&to=USD

Query Params:

  • a: amount
  • from: 来源货币代码,如 JPY, USD, CHY
  • to: 目标货币代码

得到的结果是 html,需要解析

...
<div id=currency_converter_result>100 JPY = <span class=bld>0.9300 USD</span>
...

Example

PowerShell

https://www.zhihu.com/question/23095211/answer/308511727

function ConvertTo-MyCurrency {
param(
# Default: 1
[Parameter(Mandatory=$false)]
[ValidateScript({$_ -gt 0})]
$Amount = 1,

# Default: USD
[Parameter(Mandatory=$false)]
[ValidateSet("CNY","AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYN","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNH","COP","CRC","CUP","CVE","CZK","DEM","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FIM","FJD","FKP","FRF","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","IEP","ILS","INR","IQD","IRR","ISK","ITL","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LVL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKG","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SKK","SLL","SOS","SRD","STD","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VEF","VND","VUV","WST","XAF","XCD","XDR","XOF","XPF","YER","ZAR","ZMK","ZMW","ZWL")]
[string]$From="USD",

# Default: CNY
[Parameter(Mandatory=$false)]
[ValidateSet("CNY","AED","AFN","ALL","AMD","ANG","AOA","ARS","AUD","AWG","AZN","BAM","BBD","BDT","BGN","BHD","BIF","BMD","BND","BOB","BRL","BSD","BTC","BTN","BWP","BYN","BYR","BZD","CAD","CDF","CHF","CLF","CLP","CNH","COP","CRC","CUP","CVE","CZK","DEM","DJF","DKK","DOP","DZD","EGP","ERN","ETB","EUR","FIM","FJD","FKP","FRF","GBP","GEL","GHS","GIP","GMD","GNF","GTQ","GYD","HKD","HNL","HRK","HTG","HUF","IDR","IEP","ILS","INR","IQD","IRR","ISK","ITL","JMD","JOD","JPY","KES","KGS","KHR","KMF","KPW","KRW","KWD","KYD","KZT","LAK","LBP","LKR","LRD","LSL","LTL","LVL","LYD","MAD","MDL","MGA","MKD","MMK","MNT","MOP","MRO","MUR","MVR","MWK","MXN","MYR","MZN","NAD","NGN","NIO","NOK","NPR","NZD","OMR","PAB","PEN","PGK","PHP","PKG","PKR","PLN","PYG","QAR","RON","RSD","RUB","RWF","SAR","SBD","SCR","SDG","SEK","SGD","SHP","SKK","SLL","SOS","SRD","STD","SVC","SYP","SZL","THB","TJS","TMT","TND","TOP","TRY","TTD","TWD","TZS","UAH","UGX","USD","UYU","UZS","VEF","VND","VUV","WST","XAF","XCD","XDR","XOF","XPF","YER","ZAR","ZMK","ZMW","ZWL")]
[string]$To="CNY"
)
if ($From -eq $To) {
Write-Warning -Message "Idiot! You can't convert $From to $To by yourself?!"
break
   }
$url = "https://finance.google.cn/finance/converter?a=$Amount&from=$From&to=$To"
$result = (Invoke-WebRequest -Uri $url).content -replace "(.*\n)*.*bld>|\s$To.*(.*\n)*"
Write-Host "`t$Amount $From = $result $To"
}

Last update: 2018-04-28 02:32:04 UTC