当前位置:Gxlcms > PHP教程 > 正则采集有关问题,求解

正则采集有关问题,求解

时间:2021-07-01 10:21:17 帮助过:28人阅读

正则采集问题,求解,在线等
目标页: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
  1. $s=file_get_contents('http://www.weather.com.cn/weather/101070101.shtml');<br>
  2. preg_match('/<h1 class="weatheH1" id="live">\s+(.+)\s+<\!--today5-->/s',$s,$m);<br>
  3. echo $m[1];</h1>


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


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

人气教程排行