China weather Web weather forecast API National Day according to City name Crawl City

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.