php正则表达式提取网页数据(无数据是用-表示的),/(\d+)\.(\d+)/is只能提取带小数的数据,-提不了,请教
代码如下:<tr><tdclass="borderLeftbright">客胜</td><tdclass="borderLeft"><ahref='/soccer/mat...
代码如下:
<tr >
<td class="borderLeft bright">客胜</td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">22.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">70.76</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">31.17</span></a></td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">136.47</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">84.64</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">104.48</span></a></td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">382.12</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">222.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">290.74</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="">-</span></a></td>
</tr>
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td class="borderLeft borderRight" rowspan="2">平均值</td>
<td class="borderLeft bright">主胜</td>
<td class="borderLeft">5.66</td>
<td>6.23</td>
<td class="bright">8.34</td>
<td class="borderLeft">12.19</td>
<td>14.16</td>
<td class="bright">36.58</td>
<td class="borderLeft">30.70</td>
<td>35.57</td>
<td>63.22</td>
<td class="bright">75.00</td>
<td rowspan="2" class="borderLeft">10.16</td>
<td rowspan="2" class="">8.28</td>
<td rowspan="2" class="">26.80</td>
<td rowspan="2" class="">116.67</td>
<td rowspan="2" class="">300.00</td>
</tr>
我把代码再简化一下,大概如下:我需要提取的是凡是在<td></td>中的数据,以下代码处理出来的结果应该是:22.90 ,290.74,-,300.00
<tr >
<td class="borderLeft bright">客胜</td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">22.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">290.74</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="">-</span></a></td>
</tr>
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td rowspan="2" class="">300.00</td>
</tr> 展开
<tr >
<td class="borderLeft bright">客胜</td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">22.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">70.76</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">31.17</span></a></td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">136.47</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">84.64</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">104.48</span></a></td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">382.12</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">222.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">290.74</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="">-</span></a></td>
</tr>
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td class="borderLeft borderRight" rowspan="2">平均值</td>
<td class="borderLeft bright">主胜</td>
<td class="borderLeft">5.66</td>
<td>6.23</td>
<td class="bright">8.34</td>
<td class="borderLeft">12.19</td>
<td>14.16</td>
<td class="bright">36.58</td>
<td class="borderLeft">30.70</td>
<td>35.57</td>
<td>63.22</td>
<td class="bright">75.00</td>
<td rowspan="2" class="borderLeft">10.16</td>
<td rowspan="2" class="">8.28</td>
<td rowspan="2" class="">26.80</td>
<td rowspan="2" class="">116.67</td>
<td rowspan="2" class="">300.00</td>
</tr>
我把代码再简化一下,大概如下:我需要提取的是凡是在<td></td>中的数据,以下代码处理出来的结果应该是:22.90 ,290.74,-,300.00
<tr >
<td class="borderLeft bright">客胜</td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">22.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">290.74</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="">-</span></a></td>
</tr>
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td rowspan="2" class="">300.00</td>
</tr> 展开
2个回答
展开全部
是要获取 所有 <span class="bblacktxt">XXXXXXXXXXX</span>里面的 数值 ,
还是 这个页面 里面 的所有数值?
$str =<<<DEO
<tr >
<td class="borderLeft bright">客胜</td>
<td class="borderLeft"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">22.90</span></a></td>
<td><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="bblacktxt">290.74</span></a></td>
<td class="bright"><a href='/soccer/match/579818/cs/change/236/' target='_blank'><span class="">-</span></a></td>
</tr>
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td rowspan="2" class="">300.00</td>
</tr>
DEO;
$preg = '/>(\d+\.\d+)</';
preg_match_all($preg,$str,$match);
var_dump($match);
更多追问追答
追问
不仅仅是XXXXXXXXXXX里面的 数值,还有部分是XXXX
追答
用这个正则 都行的
$str =<<<DEO
<tr class="avgobjH">
<td rowspan="2" align="left" class="borderRight"> </td>
<td class="borderLeft borderRight" rowspan="2">平均值</td>
<td class="borderLeft bright">主胜</td>
<td class="borderLeft">5.66</td>
<td>6.23</td>
<td class="bright">8.34</td>
<td class="borderLeft">12.19</td>
<td>14.16</td>
<td class="bright">36.58</td>
<td class="borderLeft">30.70</td>
<td>35.57</td>
<td>63.22</td>
<td class="bright">75.00</td>
<td rowspan="2" class="borderLeft">10.16</td>
<td rowspan="2" class="">8.28</td>
<td rowspan="2" class="">26.80</td>
<td rowspan="2" class="">116.67</td>
<td rowspan="2" class="">300.00</td>
</tr>
DEO;
$preg = '/>(\d+\.\d+)</';
preg_match_all($preg,$str,$match);
var_dump($match);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-04-02
展开全部
这个就取出了所有的2位小数的数字 要表格里的 正则换下 #>300.00</td><\/td>#is
擦,百度的显示太不好用了
&lt;?php
$con = stripslashes(file_get_contents('t.htm')); #t.htm是上面的内容,如果开了转义,就反转一下
preg_match_all('#[0-9]{1,5}\.[0-9]{1,2}#is',$con,$num);
print_r($num);
追问
问题是有些数据是空的,以横杠“-”来表示的就提取不了了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询