/**
* 提取html中a標籤的href
* @param strs
* @return
*/
public List<String> getAHref(String strs){
List<String> al=new ArrayList<String>();
String regex="<a.*?/a>";
Pattern pt=Pattern.compile(regex);
Matcher mt=pt.matcher(strs);
while(mt.find()){
String s3 = "href=\"(.*?)\"";
Pattern pt3=Pattern.compile(s3);
Matcher mt3=pt3.matcher(mt.group());
while(mt3.find())
{
System.out.println("網址:"+mt3.group().replaceAll("href=|>",""));
String u=mt3.group().replaceAll("href=|>","");
al.add(u);
}
}
return al;
}
提取HTML中所有a標籤的href鏈接
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.