日期:2014-05-17  浏览次数:20438 次

正则采集问题,求解,在线等
目标页:http://www.weather.com.cn/weather/101070101.shtml

查看其网页源码,想得到425行的数据,即“今天是2013年10月16日 星期三 农历九月十二”和621行“沈阳天气预报 (2013-10-16 18:00发布)" 和641行~765行之间主要数据。用图表示一下,见下图:


另外我自己写的一条规则,试着取了下这样的数据"沈阳天气预报 (2013-10-16 
          11:00发布)"但输入后为空数组,求指导!多谢!


------解决方案--------------------
1
$s=file_get_contents('http://www.weather.com.cn/weather/101070101.shtml');
preg_match('/<h1 class="weatheH1"  id="live">\s+(.+)\s+<\!--today5-->/s',$s,$m);
echo $m[1];


2
 preg_match('/<div class="weatherYubao"  id="7d">\s+<h1 class="weatheH1">\s+(.+?)\s+<span>/s',$s,$m);
echo $m[1];


3 不知道你想要得到什么格式的数据。