比如我的字符串为:
<html>
<body>
<table>
<tr>
<td class="sss">
<a href="4.html">444</a>
</td>
<td class="sss">
<a href="5.html">555</a>
</td>
<td class="sss">
<a href="6.html">666</a>
</td>
<td class="sss">
<a href="7.html">777</a>
</td>
</tr>
</table>
</body></html>
我的截取代码是:
Pattern p = Pattern.compile("<td class=\"sss\">.*</td>");
Matcher matcher = p.matcher(str); //str就是上面的那个网页内容
List list = new ArrayList();
while (matcher.find()) {
list.add(matcher.group());
}
为什么它不是一段一段的给我存下来啊???
怎样才能让他一段一段给我存到数组里啊????
比如:
list[1]=<td class="sss"><a href="4.html">444</a></td>
list[2]=<td class="sss"><a href="5.html">555</a></td>
list[3]=<td class="sss"><a href="6.html">666</a></td>
------解决方案--------------------
Pattern p = Pattern.compile("<td class=\"sss\">.*?</td>");