Goueg a écrit a écrit :
jsp pardon, j'ai rippé
|
un bout de classe qui va mater ton url et te renvoie le contenu <title> si ça existe
si l'url existe pas>> IOException
[pre]
public static String readTitle(URL url) throws MalformedURLException, IOException {
HttpURLConnection myConn = (HttpURLConnection) url.openConnection();
myConn.connect();
int length = myConn.getContentLength();
StringBuffer sb = new StringBuffer();
BufferedReader in = new BufferedReader(new InputStreamReader(myConn.getInputStream()));
char charBuffer[] = new char[1];
int pos = 0;
boolean bool = true;
while( in.read(charBuffer,0,1) != -1 ) {
sb.append(charBuffer[0]);
pos++;
if (sb.length()>8 && (((sb.substring(pos-8, pos)).toLowerCase()).equals("</title>" ))) break;
}
myConn.disconnect();
int start = (sb.toString().toLowerCase()).indexOf("<title>" ) + 7;
int end = (sb.toString().toLowerCase()).indexOf("</title>" );
String title = "";
if (start>=0 && end>=0) title = sb.substring(start, end);
return (StringUtils.str_replace("\n", "", title));
}
[/pre]