jeudi 24 mai 2018

Verify link integrity to local html files

Is there a way to test if a link is valid to a local html file on my hdd? I have a couple of *.htm files, in which I'm searching for all links in the document. I'm searching for all link elements and for the link from the href attribute of the element. I tried to test for a valid link with silenium and HttpURLConnection, but the href targets I want to test, are in the form of file:///C://root//example.htm. This is not working for me, because it's a local file and I got a CastException:

URL url = new URL("file:///C://root//example.htm");

    HttpURLConnection httpURLConnect = (HttpURLConnection) url.openConnection();

    httpURLConnect.setConnectTimeout(1500);

    httpURLConnect.connect();

    if(httpURLConnect.getResponseCode() == 200)
    {
        System.out.println(href + " - " + httpURLConnect.getResponseMessage());
    }

Aucun commentaire:

Enregistrer un commentaire