如何用Java实现提取网页中所有的超链接
1个回答
展开全部
import java.util.regex.*;
String baseURL = "http://...............";
Pattern pattern = Pattern.compile("href=\"(.*)\"",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(webpage_content);
while(matcher.find()){
String foundURL = matcher.group(1);
if (foundURL.startsWith("http")){
System.out.println(foundURL);
}else{
System.out.println(baseURL + foundURL));
}
}
String baseURL = "http://...............";
Pattern pattern = Pattern.compile("href=\"(.*)\"",Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(webpage_content);
while(matcher.find()){
String foundURL = matcher.group(1);
if (foundURL.startsWith("http")){
System.out.println(foundURL);
}else{
System.out.println(baseURL + foundURL));
}
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询