解析html文档的java库及范例

用这个工具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);
            }
        }

 

posted @ 2017-04-24 15:05  zhao1949  阅读(338)  评论(0编辑  收藏  举报