php正则表达式抓取网页部分内容
各位大哥谁能帮忙弄个正则表达式html代码:<tr><tdclass="rank">1</td><td><atarget="_blank"href="A1">A1</a>...
各位大哥谁能帮忙弄个正则表达式
html代码:
<tr>
<td class="rank">1</td>
<td><a target="_blank" href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a target="_blank" href="A2">A2</a>
<a target="_blank" href="A3">A3</a>
<a target="_blank" href="A4">A4</a>
</td>
</tr>
<tr>
<td class="rank">2</td>
<td><a target="_blank" href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a target="_blank" href="B2">B2</a>
<a target="_blank" href="B3">B3</a>
<a target="_blank" href="B4">B4</a>
</td>
</tr>
我想读取的到数据是
<td><a target="_blank" href="A1">A1</a></td>
<td><a target="_blank" href="B1">B1</a></td>
这部分 请问这个正则如何写
万分感激啊 展开
html代码:
<tr>
<td class="rank">1</td>
<td><a target="_blank" href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a target="_blank" href="A2">A2</a>
<a target="_blank" href="A3">A3</a>
<a target="_blank" href="A4">A4</a>
</td>
</tr>
<tr>
<td class="rank">2</td>
<td><a target="_blank" href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a target="_blank" href="B2">B2</a>
<a target="_blank" href="B3">B3</a>
<a target="_blank" href="B4">B4</a>
</td>
</tr>
我想读取的到数据是
<td><a target="_blank" href="A1">A1</a></td>
<td><a target="_blank" href="B1">B1</a></td>
这部分 请问这个正则如何写
万分感激啊 展开
4个回答
展开全部
<?php
$str = '<tr>
<td class="rank">1</td>
<td><a target="_blank" href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a target="_blank" href="A2">A2</a>
<a target="_blank" href="A3">A3</a>
<a target="_blank" href="A4">A4</a>
</td>
</tr>
<tr>
<td class="rank">2</td>
<td><a target="_blank" href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a target="_blank" href="B2">B2</a>
<a target="_blank" href="B3">B3</a>
<a target="_blank" href="B4">B4</a>
</td>
</tr>
';
preg_match_all("/<a target=\"\w*\" href=\"\w*\">\w*<\/a>/iUs",$str,$arr);
print_r($arr);
?>
$str = '<tr>
<td class="rank">1</td>
<td><a target="_blank" href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a target="_blank" href="A2">A2</a>
<a target="_blank" href="A3">A3</a>
<a target="_blank" href="A4">A4</a>
</td>
</tr>
<tr>
<td class="rank">2</td>
<td><a target="_blank" href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a target="_blank" href="B2">B2</a>
<a target="_blank" href="B3">B3</a>
<a target="_blank" href="B4">B4</a>
</td>
</tr>
';
preg_match_all("/<a target=\"\w*\" href=\"\w*\">\w*<\/a>/iUs",$str,$arr);
print_r($arr);
?>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
$str
=
'<tr>
<td
class="rank">1</td>
<td><a
target="_blank"
href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a
target="_blank"
href="A2">A2</a>
<a
target="_blank"
href="A3">A3</a>
<a
target="_blank"
href="A4">A4</a>
</td>
</tr>
<tr>
<td
class="rank">2</td>
<td><a
target="_blank"
href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a
target="_blank"
href="B2">B2</a>
<a
target="_blank"
href="B3">B3</a>
<a
target="_blank"
href="B4">B4</a>
</td>
</tr>
';
preg_match_all("/<a
target=\"\w*\"
href=\"\w*\">\w*<\/a>/iUs",$str,$arr);
print_r($arr);
?>
$str
=
'<tr>
<td
class="rank">1</td>
<td><a
target="_blank"
href="A1">A1</a></td>
<td>98678</td>
<td>101516</td>
<td>710610</td>
<td>
<a
target="_blank"
href="A2">A2</a>
<a
target="_blank"
href="A3">A3</a>
<a
target="_blank"
href="A4">A4</a>
</td>
</tr>
<tr>
<td
class="rank">2</td>
<td><a
target="_blank"
href="B1">B1</a></td>
<td>24692</td>
<td>33096</td>
<td>231669</td>>
<td>
<a
target="_blank"
href="B2">B2</a>
<a
target="_blank"
href="B3">B3</a>
<a
target="_blank"
href="B4">B4</a>
</td>
</tr>
';
preg_match_all("/<a
target=\"\w*\"
href=\"\w*\">\w*<\/a>/iUs",$str,$arr);
print_r($arr);
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<td><a target="_blank".*
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
abcdefg
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询