Get the city code of the town
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');//must dripcurl_setopt ($ch, Curlopt_cookie,'isexist=1');//preferably with more stability.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='Guangzhou'; $url='http://toy1.weather.com.cn/search?cityname='. UrlEncode ($city).'&callback=jsonp'. Time (). Mt_rand ( -,999).'&_='. Time (). Mt_rand ( -,999); $result= Explode ('~', substr (Strtolower (Curl ($url)), -, -4) ); Var_export ($result);Exit ();
Weather interface provided by the National Weather
Interface Address:
Http://www.weather.com.cn/data/sk/101010100.html
Http://www.weather.com.cn/data/cityinfo/101010100.html
XML interface
Http://flash.weather.com.cn/wmaps/xml/china.xml This is the root node of the National weather, listing all the provinces, where the Pyname field is the file name of each province's XML, such as the Beijing in Beijing, That means Beijing's XML address is the weather in Http://flash.weather.com.cn/wmaps/xml/beijing.xml province, which lists data for each city in the province, and Beijing lists the districts. TMP1 is the lowest temperature low, TMP2 is the highest temperature, the URL is very important, we'll talk about it later. State1 and State2 are gods horses, each of which represents a weather phenomenon. The weather is very much, I want to analyze it all, and then give up the idea directly. Because I saw the code of a city's weather phenomenon is 26 ... I now know 0. Sunny 1. Cloudy 2. Overcast 6. Sleet 7. Rain 8. Cloudy 13. Snow 14. Snow which later found that this useless, the main role of this number is to retrieve pictures!!!
China weather Web weather forecast API National Day according to City name Crawl City