1 /** 2 * 提取HTML標簽的屬性值 3 * @param source HTML標簽內容 4 * "<span rid="1177217865" __cid="cJ3e2aq" class="cJ3e2aq">@蒼井空 </span>" 5 * @param element 標簽名稱 a 6 * @param attr 標簽屬性 title 7 * @return 8 */ 9 public static List<String> match(String source, String element, String attr) { 10 List<String> result = new ArrayList<String>(); 11 String reg = "<" + element + "[^<>]*?\\s" + attr + "=['\"]?(.*?)['\"]?\\s.*?>"; 12 Pattern pt = Pattern.compile(reg); 13 Matcher m = pt.matcher(source); 14 while (m.find()) { 15 String r = m.group(1); 16 result.add(r); 17 } 18 return result; 19 }