public static String relative2AbsolutePath(String content, String url, String tag, String property) throws URISyntaxException,
MalformedURLException {
String newContent = "";
if (content != null && content.trim() != "") { URI base = new URI(url);// 基本网页搜索URI
Document doc = Jsoup.parse(content); for (Element ele : doc.getElementsByTag(tag))
{
String elePropValue = ele.attr(property);
if (!elePropValue.matches("^(https?|ftp):(\\\\|//).*$")) {
URI abs = base.resolve(elePropValue);// 解析相对URL,得到绝对URI
ele.attr(property, abs.toURL().toString());
}
}
newContent = doc.html();
}
return newContent;
}
public static String relative2AbsolutePath(String content, String url) { try { content = Tool.relative2AbsolutePath(content, url, "a", "href"); .
jsoup获取到相对路径怎么变成绝对路径
最新推荐文章于 2022-07-02 13:17:00 发布