zoukankan      html  css  js  c++  java
  • php 抓取天气情况 www.weather.com.cn

    <?php
    
    
    print_r(getweather(101120501));
    
    
    /**
     * Server 天气情况获取函数
     * @param unknown $city
     */
    function getweather($city){
    	$url = "http://www.weather.com.cn/weather1d/".$city.".shtml";
    	$result = file_get_contents($url);
    	$result = explode("<li class='dn on' data-dn='todayT'>",$result);
    	$result = explode("<div class="m m2" id="2_3d">",$result[1]);
    	$result = mb_convert_encoding($result[0],"GBK","UTF-8");
    	$first = explode("<div class="slid"></div>",$result);
    	//print_r($first);exit;
    	$w1 = get_we_info($first[0]);
    	$w2 = get_we_info($first[1]);
    	$week = mb_substr($w1[0],-2);
    	$arr['w_week']  = $week;
    	$arr['w_day1']  = trim($w1[1]);
    	$arr['w_day2']  = trim($w2[1]);
    	$arr['w_type1'] = trim($w1[2]);
    	$arr['w_type2'] = trim($w2[2]);
    	$arr['w_temperature1']= trim($w1[3]);
    	$arr['w_temperature2']= trim($w2[3]);
    	return $arr;	
    }
    /**
     * 每天的具体天气状况(今天 白天->今天 夜间)
     * @param unknown $info
     * @return string
     */
    function get_we_info($info){
    	$w_info=explode("</h1>",$info);
    	$we_arr[0] = strip_tags($w_info[0]);
    	$w_info=explode("</h2>",$w_info[1]);
    	$we_arr[1] = strip_tags($w_info[0]);
    	$w_info = explode("<p class="tem">",$w_info[1]);
    	$we_arr[2] = strip_tags($w_info[0]);
    	$w_info=explode("<i>",$w_info[1]);
    	//$w_info=explode("<p class="win">",$w_info[1]);
    	$we_arr[3]=strip_tags($w_info[0]);
    	return $we_arr;
    }
    
    
    
    ?>

  • 相关阅读:
    51nod1089(最长回文子串之manacher算法)
    51nod1088(最长回文子串)
    51nod1256(乘法逆元)
    51nod1085(01背包)
    51nod1079(中国剩余定理)
    数据的特征工程
    30种提高mysql处理速度的方法
    机器学习资料
    python3.6安装-windows
    python import sklearn出错 "ImportError: DLL load failed: 找不到指定的模块。
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5204646.html
Copyright © 2011-2022 走看看