jsoup 提取 html中的所有链接

try {
            Document doc = (Document) Jsoup.connect(url).get();
            Elements links = ((Element) doc).select("a[href]");
            for (Element link : links) {
                  String linkHref = link.attr("href");
                  String linkText = link.text();
                  System.out.println(linkText+"-"+linkHref);
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

你可能感兴趣的:(java)