獲取城市的城市代碼了html
function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_REFERER, 'http://www.weather.com.cn/forecast/index.shtml');//必須滴 curl_setopt($ch, CURLOPT_COOKIE,'isexist=1');//最好帶上 比較穩定 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0'); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); return $data; } $city = '廣州'; $url = 'http://toy1.weather.com.cn/search?cityname='.urlencode($city).'&callback=jsonp'.time().mt_rand(100, 999).'&_='.time().mt_rand(100, 999); $result = explode('~', substr(strtolower(curl($url)), 28, -4)); var_export($result); exit();
國家氣象局提供的天氣預報接口json
接口地址:curl
http://www.weather.com.cn/data/sk/101010100.htmlpost
http://www.weather.com.cn/data/cityinfo/101010100.htmljsonp
XML接口 編碼
http://flash.weather.com.cn/wmaps/xml/china.xml 這個是全國天氣的根節點,列出全部的省,其中的pyName字段是各個省XML的文件名,好比北京的是beijing,那就意味着北京的XML地址爲 http://flash.weather.com.cn/wmaps/xml/beijing.xml 一個省的天氣,其中列出該省各個市的數據,北京就列出各個區。 tmp1是最低溫低,tmp2是最高溫度,url很是重要,咱們一下子再說。state1和state2是神馬轉神馬,每一個數表明一個天氣現象。天氣現象 很是多,我本想所有分析出來,後來直接放棄了這個想法。由於我看到了一個城市的天氣現象的編碼是26...我如今知道的有0.晴 1.多雲 2.陰 6.雨夾雪 7.小雨 8.中雨 13.陣雪 14.小雪 其中後來發現知道這個沒用,這個數字的主要做用是檢索圖片的!!!url
原文連接:https://www.cnblogs.com/137dawn/p/6413744.htmlspa