« Accueil | Touillettes » | Ascenseur, ascenseur ! » | RDF Mégalo ? » | Whoops ! sorry that post is not available for some... » | Whoops ! sorry that post is not available for some... » | Des âneries » | Chaos Cantine Club (2) » | Chaos Cantine Club » | L'allégorie d'un geekisme » | Minimisons notre humour à posteriori »

Bus

Dans combien de temps passe le 72? Enfin la réponse en Java.





import java.net.*;

import java.io.*;
import java.util.*;


class Code {


static String getTruc() {
String s="";
try {
// Create a URL for the desired page
URL url = new URL("http://www.ratp.info/horaires/index.php?etape=res_bustram_ssotr&act=act_actua&reseau=BUS&dem=dem3&ligne=72&arr=72_141_145&dir=A&libligne=HOTEL+DE+VILLE+%2F+PARC+DE+ST+CLOUD&libarr=RADIO+FRANCE&libdir=HOTEL+DE+VILLE");

// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
s += str;
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return s;
}

static Vector extraitDates(String s) {
Vector v = new Vector();
int ind=0,lastInd=0,ind2;
String t;
while(true) {
ind = s.indexOf(" mn<div>",lastInd);
if(ind==-1) {
break;
}
ind2=s.lastIndexOf(">",ind);
t = s.substring(ind2+1,ind);
//System.out.println(ind2+" "+ind+" "+t);
v.add(t);
lastInd = ind+1;
}
return v;
}

public static void main(String[] args) {
String s = getTruc();
System.out.println(extraitDates(s));
}

}


On notera la clarté et la présentation, examplaires, du code.

J'ai la même en php :-P

C'est rude à suivre, parfois, les blogs de thésards en informatique...
Help ! j'ai pas compris la blague !

Chez moi ça ne marche que si je parse avec "mn</div>" et non "mn<div>"... Une fonctionnalité ? :D

damn, en mettant encodant les entités je me suis fourvoyé, /div bien entendu!

elzriel qui gagne un bisou à venir chercher au lip 6 :)

Enregistrer un commentaire

Navigation

Les réflexions de la machine à café :

Recent Comments

A consommer avec modération tout abus sera puni, bloguer tue et réduit la fertilité, n'oubliez pas la damepipi a l'entrée etc. etc.