php 用正则表达式提取网页内容
<liclass="blackArea"data-sourcelatest-elem="item"data-tvid="694641300"data-vid="7b0b5...
<li class="blackArea" data-sourcelatest-elem="item" data-tvid="694641300" data-vid="7b0b59d2ef0cb1152368ca9be9a4ae76" data-idx="4" data-sourcelatest-month="" data-delegate="videoPlayList">
<p class="video_position video_rb"><span class="v_name" rseat="xj_ty3">第2017-06-08期</span></p>
<h3> <a title="微体兔新版馋嘴小面" href="javascript:void(0);" rseat="xj_vn3">微体兔新版馋嘴小面</a> </h3>
</li>
怎么提取<li>中的data-tvid,data-vid,以及<p>和<h3>中的内容呢 展开
<p class="video_position video_rb"><span class="v_name" rseat="xj_ty3">第2017-06-08期</span></p>
<h3> <a title="微体兔新版馋嘴小面" href="javascript:void(0);" rseat="xj_vn3">微体兔新版馋嘴小面</a> </h3>
</li>
怎么提取<li>中的data-tvid,data-vid,以及<p>和<h3>中的内容呢 展开
2个回答
展开全部
$str = '<li class="blackArea" data-sourcelatest-elem="item" data-tvid="694641300" data-vid="7b0b59d2ef0cb1152368ca9be9a4ae76" data-idx="4" data-sourcelatest-month="" data-delegate="videoPlayList">
<p class="video_position video_rb"><span class="v_name" rseat="xj_ty3">第2017-06-08期</span></p>
<h3> <a title="微体兔新版馋嘴小面" href="javascript:void(0);" rseat="xj_vn3">微体兔新版馋嘴小面</a> </h3>
</li>';
$pattern = "/[\s\S]*<li[^>]+data-tvid[=\"\']+([^\"\']*)[\"\'][^>]*data-vid[=\"\']+([^\"\']*)[\"\'][\s\S]*/i";
$tvid = preg_replace($pattern, "$1", $str);
$vid = preg_replace($pattern, "$2", $str);
$reg = "/[\s\S]*<p[^>]*>((?:(?!<\/p>)[\s\S])*)<\/p>[\s\S]*/i";
$p = preg_replace($reg, "$1", $str);
$reg = "/[\s\S]*<h3[^>]*>((?:(?!<\/h3>)[\s\S])*)<\/h3>[\s\S]*/i";
$h3 = preg_replace($reg, "$1", $str);
echo $tvid."\n".$vid."\n".$p."\n".$h3;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |