how do i use jsoup to parse internal and external hyperlinks closed?

You can try Document.getElementsByAttributeValueMatching() method to find element by attribute name and attribute value with proper regex.

For example, find all elements have attribute name is “href” and attribute value starting with https://example.com

    Document document = Jsoup.connect("https://example.com").get();
    Elements elements = document.getElementsByAttributeValueMatching("href", "^https://example.com");

    for (Element element : elements) {
        System.out.println(element.attr("href"));
    }

There are also some similar methods:

Document.getElementsByAttributeValueStarting()
Document.getElementsByAttributeValueContaining()

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top