php 抓取天气情况 www.weather.com.cn
2014-08-19 08:39
405 查看
<?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; } ?>
相关文章推荐
- php 抓取天气情况 www.weather.com.cn
- php 从http://www.weather.com.cn/上抓取天气情况
- python获取网站http://www.weather.com.cn 城市 8-15天天气
- 天气接口 http://flash.weather.com.cn/wmaps/xml/china.xml
- 天气预报接口(weather.com.cn)
- 用"http://m.weather.com.cn/data/" + cityCode + ".html"获取城市天气
- 用"http://m.weather.com.cn/data/" + cityCode + ".html"获取城市天气
- 关于 “中国天气网 - www.weather.com.cn” 相关的 API 总结
- 使用weather.com.cn数据实现的简易天气demo
- 收藏常用正则表达式 转自shuguang http://www.osphp.com.cn/read.php/453.htm
- 关于中国天气(Weather.com.cn)的查询
- 编写安全 PHP 应用程序的七个习惯(转自 IBM Thoughtworks http://www.ibm.com/developerworks/cn/opensource/os-php-secure-apps/?S_TACT=105AGX52&S_CMP
- 网络蜘蛛原理~ 转 http://www.sysinfo.cn/show.php?id=35
- 新建学习娱乐网站 http://www.pnonline.com.cn
- XCodeFactory下载地址:http://www.tomore.com/dispdocnew.php?id=29469
- 太平洋网站www.pconline.com.cn
- 网管员世界http://www.netadmin.com.cn/
- 面试www.Pconline.com 和 www.IT.com.cn
- 用PHP模拟登陆(引自http://www.tianjiaonet.com)
- 友好日记本(http://www.kindtools.com/cn/index.html)