Bonjour,
J’ai souci de boucle qui ne veut pas boucler.
Mon programme :
Le programme doit, à partir de l’URL d’une page Google, extraire les différents liens qui se trouvent dans son code source. (Utilisation d’un client http en java, bufferedReader et etc…)
J’ai récupéré chaque ligne qui m’intéresse et les ait stocké dans un vecteur. Afin d’extraire les liens, je fais une recherche par encadrement via searchtab1 et searchtab2 afin de connaitre la position exacte du lien à extraire.
La partie du code qui bloque :
Le code fonctionne mais l’incrémentation ne veut pas se faire. J’ai bien tenté un for mais cela ne marche pas non plus. J’ai même fait attention à la position du break ; .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71 //tab : ligne à analyser //searchtab1 : mot recherché 1 //searchtab2 : mot recherché 2 int n = 0; do { System.out.println("--------------- " + n + " ---------------"); char[] tab; tab = ((String) vect.elementAt(n)).toCharArray(); //System.out.println(vect.elementAt(n)); System.out.println("--------------------------------------------------------"); for (int i = 0; i < tab.length; i++) { int cpt1 = 0; int P1 = -1; int P2 = -1; int B2 = -1; for (int j = 0; j < searchtab1.length; j++) { P1 = -1; if (searchtab1[j] == tab[i + j]) { cpt1 = cpt1 + 1; } if (cpt1 == searchtab1.length) { P1 = i + searchtab1.length; //System.out.println("ETAPE 1"); //System.out.println("\"" + search1 + " de longueur " + searchtab1.length + " trouvé de " + P1 + " à " + (P1 + searchtab1.length)); } } if (P1 > -1) { P2 = -1; //System.out.println("ETAPE 2"); int cpt2 = 0; for (int k = P1; k < tab.length; k++) { cpt2 = 0; for (int l = 0; l < searchtab2.length; l++) { if (searchtab2[l] == tab[k + l]) { cpt2 = cpt2 + 1; } if (cpt2 == searchtab2.length) { P2 = k; //System.out.println("\"" + search2 + "\" de longueur " + searchtab2.length + " trouvé de " + P2 + " à " + (P2 + searchtab2.length)); B2 = P2; if (searchtab2.length > 1) { B2 = P2 + searchtab2.length - 1; } } } if (cpt2 == searchtab2.length) { break; } } } if (P1 >= 0 && B2 >= 0) { //System.out.println("ETAPE 3"); affiche = ""; System.out.println("De " + P1 + " à " + B2); for (int x = P1; x < B2; x++) { affiche = affiche + tab[x];} System.out.println(affiche); System.out.println("--------------------------------------------------------"); } } System.out.println("Au suivant !!!!!!!!"); n = n + 1; } while (n < vect.size());
Si quelqu’un avait la gentillesse de me dire où je me suis planté, je lui serais reconnaissant.
Partager