0
while (it.isValid()) {
        SimpleAttributeSet s = (SimpleAttributeSet) it.getAttributes();
        linkURLs = (String) s.getAttribute(HTML.Attribute.HREF);

        if (linkURLs != null) {

            System.out.println(linkURLs);

        }
        it.next();

    }

This loop shows the URLs.

How to display the getResponseCode () for each address? It must be done in a loop? Can anyone write such code? I do not know how you go about it.

1 Answer 1

4

You're going to need to open those URLs, but be warned that they could be relative or protocol-relative (unless your library does this for you). Once you rebuild the URL, do

URL url = new URL(urlStr);

// Might be a good idea to validate the connection type before casting
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.getResponseCode();
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Now I understand what this is all about.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.