zoukankan      html  css  js  c++  java
  • 根据城市获取天气

     

    获取城市的城市代码了

    复制代码
    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

  • 相关阅读:
    什么是内部类
    "=="和equals方法究竟有什么区别?
    SWFUpload乱码问题的解决
    xStream转换XML、JSON
    Java文件下载
    笔记摘录
    Javascript 函数传参问题
    JQUERY伸缩导航
    ruby关于flip-flop理解上一个注意点
    ruby 使用Struct场景
  • 原文地址:https://www.cnblogs.com/cczlovexw/p/10999264.html
Copyright © 2011-2022 走看看