码迷,mamicode.com
首页 > 其他好文 > 详细

根据城市获取天气

时间:2019-06-10 18:31:06      阅读:113      评论:0      收藏:0      [点我收藏+]

标签:cas   class   firefox   and   tran   too   dex   jin   url   

获取城市的城市代码了

技术图片
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();
技术图片

国家气象局提供的天气预报接口

接口地址:

http://www.weather.com.cn/data/sk/101010100.html

http://www.weather.com.cn/data/cityinfo/101010100.html

 

 

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.小雪 其中后来发现知道这个没用,这个数字的主要作用是检索图片的!!!

 

原文链接:https://www.cnblogs.com/137dawn/p/6413744.html

根据城市获取天气

标签:cas   class   firefox   and   tran   too   dex   jin   url   

原文地址:https://www.cnblogs.com/cczlovexw/p/10999264.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!