• 根据城市获取天气


     

    获取城市的城市代码了

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

  • 相关阅读:
    avalov+require实现tab栏
    动态加载js,css
    Zepto.js
    Linux 的文件和目录管理类命令
    shell 的基本理解
    Linux 日期时间命令
    Linux 关机命令
    type 命令
    命令类型即使用帮助
    cd 命令
  • 原文地址:https://www.cnblogs.com/cczlovexw/p/10999264.html
Copyright © 2020-2023  润新知