MSN Weather API

user-pic
Vote 0 Votes

從 3/22 開始, 使用 Google Weather API 就抓不到台中的資料, 不曉得為什麼, 其他城市正常
http://www.google.com.tw/ig/api?weather=Taichung
會顯示「資訊暫時無法使用」
只好改用 MSN 的 API, 回傳的結果一樣是 XML
http://weather.msn.com/data.aspx?wealocations=wc:TWXX0019&weadegreetype=C
wc: 後面接城市代碼, 上例 TWXX0019 就是台中, weadegreetype=C 是℃
其他城市代碼可以在 weather.com 找到,
這裡 也有人貼了清單

使用 PHP 取得台中的溫度、濕度
$xml = simplexml_load_file('http://weather.msn.com/data.aspx?wealocations=wc:TWXX0019&weadegreetype=C');
$current = $xml->xpath("/weatherdata/weather");
$temperature=$current[0]->current[temperature];
$humidity=$current[0]->current[humidity];

Leave a comment

About this Entry

This page contains a single entry by Pank published on March 31, 2011 2:19 PM.

ShutterCounter.com was the previous entry in this blog.

Atheros AR8131 ethernet driver for CentOS 5.5 x86_64 is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Monthly Archives