1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| import java.net.*;
import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLConnectionReader {
public static void main(String[] args) throws Exception {
URL yahoo = new URL("http://deptinfo.unice.fr/~grin/mescours/linfo/poo/projets/listeetudiants.html");
URLConnection yc = yahoo.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
{
StringBuilder codeHTML = new StringBuilder();
String expReguliere = ".*?<tr[^>]*>(.*?)</tr>.*?";
Pattern p = Pattern.compile(expReguliere);
while ((inputLine = in.readLine()) != null) {
codeHTML.append(inputLine);
}
Matcher m = p.matcher(codeHTML.toString());
while(m.find())
// System.out.println(m.group(1).replaceAll("(<[^>]*>)|(</[a-z]*>)", " "));
Lecteur.ajouterLigne(m.group(1).replaceAll("(<[^>]*>)|(</[a-z]*>)", " "));
// }
// System.out.println(inputLine);
//
// Lecteur.getListeEtudiants().remove(0);
//for(int i=0; i<Lecteur.getListeEtudiants().size() ; i++){
// System.out.println(Lecteur.getListeEtudiants().get(i));
}
in.close();
}
} |
Partager