import java.net.*; import java.io.*; import java.util.regex.*; import java.util.*; public class Veebilugeja5{ // static String aadress="http://www.hk.tlu.ee/index.php"; static String algaadress="http://minitorn.tlu.ee/~jaagup/kool/"; static String aadress; static List uuritud=new LinkedList(); static List ootel=new LinkedList(); static List vigased=new LinkedList(); static Pattern muster=Pattern.compile("href=[\\\"']([^\\\"']+)"); public static void uuriRida(String rida){ Matcher m=muster.matcher(rida); while(m.find()){ try{ String viide=m.group(1); if(!viide.startsWith("http://")){ viide=new URL(new URL(aadress), viide).toString(); } if(viide.startsWith("http://")){ try{ new URL(viide).openStream(); if(ootel.contains(viide) || uuritud.contains(viide)){ System.out.println("Juba olemas "+viide); } else if(new URL(algaadress).getHost().equals(new URL(viide).getHost())){ ootel.add(viide); System.out.println("Ootele "+viide); } else { System.out.println("Kaugviide "+viide); } } catch(Exception e){ System.out.println("Ei saa avada: "+viide); vigased.add(viide); } } else { System.out.println("Pole veebiviide: "+viide); } }catch(MalformedURLException ex){ System.out.println("Vigane aadress: "+ex.getMessage()); } } } public static void main(String argumendid[]) throws IOException{ ootel.add(algaadress); while(ootel.size()>0){ aadress=ootel.remove(0); System.out.println("Uurib: "+aadress); BufferedReader sisse=new BufferedReader( new InputStreamReader(new URL(aadress).openStream()) ); String rida=sisse.readLine(); while(rida!=null){ uuriRida(rida); rida=sisse.readLine(); } } System.out.println("Vigased: "+vigased); } }