我正在编写一个脚本,该脚本具有使用天气 API 的功能。目前我只设法用 curl
解决了这个问题,但我最近注意到我无法访问需要运行脚本的 curl
。还有其他方法可以解决这个问题吗?我的代码是这样的:
weatherLondon()
{
echo "<h3>Weather in London</h3>"
(( $# )) || set -- "London,UK"
echo "Location: ${1//,/, }"
curl -s "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=$1" | perl -ne 's/&deg;/°/g;
s/ \(\d+°F\)//g;
/<title>([^<]+)/ && printf "%s: ",$1;
/<fcttext>([^<]+)/ && print $1,"\n"';
}
我对 bash 和 API 都很陌生
最佳答案
您可以使用旧的 wget
。它应该是几乎每个 Linux 发行版的一部分(除非没有被管理删除)。将您的 curl 语句替换为:
wget -q -O - "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=$1"
-O -
将输出设置为标准输出,-q
像 curl 的 -s
关于bash - 在没有 curl 的情况下在 Bash 中使用 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20202124/