コマンドラインで都市の天気コードを探す

コマンドラインで都市の天気コードを探す

FRXX3828コマンドラインで都市の天気コード(例:Roissy-en-France、FR、コードなど)を見つけようとしています。

これまで、次のツールを試してみました。https://askubuntu.com/questions/390329しかし、それらのどれも実際に天気コードを表示しません。

助けてください?

ベストアンサー1

これはやや醜いが動作するようです。

# create a temporary file to store the curl output
$ tmpfile=$(mktemp)
# perform a search in the site https://weather.codes in the url
$ curl -v --silent "https://weather.codes/search/?q=Roissy+en+France" > "$tmpfile" 2> /dev/null
# extract the code
$ sed -z 's,.*<span>\([^<>]*\)</span>.*,\1,g' "$tmpfile"
FRXX3828

もちろん、ページでHTMLコードや検索方法が変更されても機能しません。

おすすめ記事