解析html文档的java库及范例

时间:2023-12-21 08:10:50

用这个工具jsoup

<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>

java范例

        Document document = Jsoup.parse(htmlContent);
Elements elements = document.getElementsByTag("img");
if (null != elements) {
for (Element element : elements) {
String src = element.attr("src");
src = src.replace(baseUrl, "");
src = src.replace("/api/", "/");
src = src.replaceAll("[&|?]access_token=.*$", "");
element.attr("src", src);
}
}