|
- <?php
- require_once('global.php');
- $url='http://qq.ip138.com/weather/guangdong/HeYuan.htm'; //抓取目标地址 可以自己换个
- update_weather($url);
- showmsg('更新天气缓存完毕');
- function update_weather($url)
- {
- $con = file_get_contents($url);
- preg_match('~<table width="700" borderColorDark="#ffffff".*?>(.*?)</table>~s',$con,$table);
- preg_match_all('~<tr.*?>(.*?)</tr>~s',$table[1],$trs);
- $i=0;
- $array = array();
- foreach ($trs[1] as $tr)
- {
- ++$i;
- preg_match_all('~<t[dh].*?>(.*?)</t[dh]>~s',$tr,$tds);
- $array[0][] =$tds[1][1]; //这边可以抓取多天的 这个为1天的
- }
- preg_match_all('~<br/>(.*?)</td>~s',$trs[1][1],$tys);
- $array[0][4] = $tys[1][0];
- $array[0][1] = get_img($array[0][1]);
- $tmptianqi = '河源天气'."{$array[0][2]}";
- $tmptianqi.= "<img align=\"absmiddle\" src=\"{$array[0][1]}\" alt=\"{$array[0][4]}\" height=\"22\" width=\"30\" />{$array[0][4]}";
- $tmp = "\$tianqi = '$tmptianqi'";
- pwCache::setData(D_P . 'data/bbscache/cache_toutiao.php',"<?php\r\n".$tmp."\r\n?>");
- }
- function get_img($str)
- {
- preg_match('~src=["\']?(.*?)["\']? ~s',$str,$p);
- $img = 'images/weather/';
- return $img.pathinfo($p[1],PATHINFO_BASENAME);
- }
- ?>
可以加到计划任务里 一天执行一次
|