probleme de recupération d'une valeur sur une page web
Bonjour a tous,
Je tente actuellement de monter un petit site de bourse en ligne et je bloque sur une partie essentielle du projet a savoir la partie qui va lire et récupère la valeur d'une action sur un site tel que les echos.fr. Voila tout marché mais recemment sa bug, je recupère une exception et plus rien....
Si un expert passe par la:
Code:
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
|
import java.net.*;
import java.text.DecimalFormat;
import java.io.*;
public class LectureURL {
public static void main(String args[]){
System.out.println(getVal("http://bourse.lesechos.fr/bourse/cours.jsp?Code=FR0004061513&Place=00025-TD&Codif=ISI"));
}
static float getVal(String url){
try{
URL page = new URL(url);
URLConnection urlConx = page.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConx.getInputStream()));
String inputLine, truc;
while ((inputLine = in.readLine()) != null){
if (inputLine.contains("<TD class=\"TABLEAU-SEANCE-15\" align=\"center\">")){
inputLine = in.readLine().trim();
inputLine = inputLine.substring(0,inputLine.length()-1);
inputLine = inputLine.replaceAll(Character.toString((char)160), "");
System.out.println(url + inputLine);
float val = (float)Float.parseFloat(inputLine.replaceAll(",", "."));
//System.out.println(val + "valeur");
return val;
}
}
return 0;
}
catch(Exception e){
System.out.println(url);
System.out.println(e);
return 0;
}
}
} |
Citation:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
Merci davance !!