81,094
社区成员
发帖
与我相关
我的任务
分享
// 匹配昵称
// 网页中的内容:<span class="actual_persona_name">nicakname</span>
pattern = Pattern.compile("actual_persona_name.+?>(.+?)</span>");
matcher = pattern.matcher(content);
if (matcher.find()) {
nickname = matcher.group(1);
}
现在我想匹配数量count,也就是下面的29。网页中内容如下:
<a href="http://steamcommunity.com/profiles/76561198080422617/games/?tab=all">
<span class="count_link_label">游戏</span>
<span class="profile_count_link_total">29</span>
</a>
直接匹配<span class="profile_count_link_total">29</span>不行因为页面多处存在。也就是要匹配****?tab=all这个标签的子标签,正则怎么写?
String content="<a href=\"http://steamcommunity.com/profiles/76561198080422617/games/?tab=all\">\n" +
" <span class=\"count_link_label\">游戏</span> \n" +
" <span class=\"profile_count_link_total\">29</span>\n" +
"</a>";
Pattern pattern = Pattern.compile(".*?tab=all.*?profile_count_link_total\">(.*?)</span",Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = pattern.matcher(content);
if (matcher.find()) {
System.out.println(matcher.group(1));
}