IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

Parser page HTML - HtmlAgility


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Mai 2010
    Messages
    62
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 62
    Par défaut Parser page HTML - HtmlAgility
    Bonjour à tous,

    j’essaye depuis des jours de récupérer les cellules d'un tableau HTML dans un array mais malheureusement sans succès.
    Ceci avec le pack HTMLAGILITY.

    Si quelqu'un peut me débloquer la situation, je suis preneur.



    j'utilise teste ce code pour le tableau HTML ci-dessous

    mon code :
    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
        Dim wc = New WebClient()
            Dim doc = New HtmlDocument()
     
            Using stream = wc.OpenRead("MON SITE")
     
                doc.Load(stream)
            End Using
     
     
            Dim web = New HtmlWeb
     
     
            For Each tble As HtmlNode In doc.DocumentNode.SelectNodes("//table")
     
                For Each row As HtmlNode In tble.SelectNodes("./tr")
                    'On parcoure les cellules
                    For Each cell As HtmlNode In row.SelectNodes("./td")
     
                        Dim b = cell.InnerText
     
                        MsgBox(b)
                    Next
                Next
            Next

    Tableau HTML :
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    <table>
        <thead class="partant">
        <tr class="participant-header">
     
     
            </td>
            <td class="column-separator optional"> </td>
            <td class="mode-b optional"> </td>
            <td class="advanced-mode-a optional"> </td>
        </tr>
        </thead>
        <tbody> <tr class="ligne-participant odd favorite"><td class="txtC"><strong>1</strong></td>
    <td>
        <span class="name unit" title="voir la fiche de CLASS CONTI">
            class conti
        </span>
        <span class="unitRight paddingRight5">
            <b class=""> </b>
            <b class=""> </b>
     
        </span>
    </td>
    <td class="txtC">
     
    <td class="txtC"><b class="SANS_OEILLERES"> </b></td>
    <td class="txtC">H</td>
    <td class="txtC">3</td>
    <td>
        <span title="J.REVELEY">j.reveley</span>
    </td>
    <td class="txtC">70</td>
    <td class="txtC">-</td>
    <td class="txtC">-</td>
    <td><span title="G.MACAIRE (S)">g.macaire (s)</span></td>
    <td class="txtC">
      <span title="1h">
    	  1h
      </span>
    </td>
    <td class="txtC rapport-probable">2,3</td>
    <td class="txtC rapport-probable last">1,8</td>
    <td class="column-separator optional"></td>
    <td class="txtC mode-b optional">
        <div id="participant-base-1" class="participant-selector">
            <b data-type="base" class="participant-check base"> </b>
        </div>
    </td>
    <td class="txtC advanced-mode-a optional">
        <div id="participant-associate-1" class="participant-selector">
            <b data-type="associate" class="participant-check associate"> </b>
        </div>
    </td>
    </tr><tr class="ligne-participant even"><td class="txtC"><strong>2</strong></td>
    <td>
        <span class="name unit" title="voir la fiche de COURVITE">
            courvite
        </span>
        <span class="unitRight paddingRight5">
            <b class=""> </b>
            <b class=""> </b>
     
        </span>
    </td>
    <td class="txtC">
     
    </td>
    <td class="txtC"><b class="SANS_OEILLERES"> </b></td>
    <td class="txtC">H</td>
    <td class="txtC">3</td>
    <td>
        <span title="A.CHITRAY">a.chitray</span>
    </td>
    <td class="txtC">68</td>
    <td class="txtC">-</td>
    <td class="txtC">-</td>
    <td><span title="G.CHEREL">g.cherel</span></td>
    <td class="txtC">
      <span title="2h6p9p">
    	  2h6p9p
      </span>
    </td>
    <td class="txtC rapport-probable">5,8</td>
    <td class="txtC rapport-probable last">8,6</td>
    <td class="column-separator optional"></td>
    <td class="txtC mode-b optional">
        <div id="participant-base-2" class="participant-selector">
            <b data-type="base" class="participant-check base"> </b>
        </div>
    </td>
    <td class="txtC advanced-mode-a optional">
        <div id="participant-associate-2" class="participant-selector">
            <b data-type="associate" class="participant-check associate"> </b>
        </div>
    </td>
    </tr><tr class="ligne-participant odd"><td class="txtC"><strong>3</strong></td>
    <td>
        <span class="name unit" title="voir la fiche de SAINT XAVIER">
            saint xavier
        </span>
        <span class="unitRight paddingRight5">
            <b class=""> </b>
            <b class=""> </b>
            A
        </span>
    </td>
    <td class="txtC">
     
    </td>
    <td class="txtC"><b class="SANS_OEILLERES"> </b></td>
    <td class="txtC">H</td>
    <td class="txtC">3</td>
    <td>
        <span title="S.COLAS">s.colas</span>
    </td>
    <td class="txtC">68</td>
    <td class="txtC">-</td>
    <td class="txtC">-</td>
    <td><span title="E.CLAYEUX (S)">e.clayeux (s)</span></td>
    <td class="txtC">
      <span title="6h3h">
    	  6h3h
      </span>
    </td>
    <td class="txtC rapport-probable">8,3</td>
    <td class="txtC rapport-probable last">9,2</td>
    <td class="column-separator optional"></td>
    <td class="txtC mode-b optional">
        <div id="participant-base-3" class="participant-selector">
            <b data-type="base" class="participant-check base"> </b>
        </div>
    </td>
    <td class="txtC advanced-mode-a optional">
     
        <div id="participant-base-13" class="participant-selector">
            <b data-type="base" class="participant-check base"> </b>
        </div>
    </td>
    <td class="txtC advanced-mode-a optional">
        <div id="participant-associate-13" class="participant-selector">
            <b data-type="associate" class="participant-check associate"> </b>
        </div>
    </td>
    </tr></tbody>
     
    </table>

  2. #2
    Membre Expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Par défaut
    Salut,

    il faudrait savoir exactement où ton code se rate.
    Ça plante ? Ça ne fait rien ? Ça fait un truc inattendu ?
    Le SelectNodes("//table") te renvoie bien quelque chose ?
    (j'ai quelques doutes sur cette ligne du fait qu'il y ait peu de chance de trouver un élément table à la racine du XML)

  3. #3
    Membre confirmé
    Inscrit en
    Mai 2010
    Messages
    62
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 62
    Par défaut
    Citation Envoyé par jopopmk Voir le message
    Salut,

    il faudrait savoir exactement où ton code se rate.
    Ça plante ? Ça ne fait rien ? Ça fait un truc inattendu ?
    Le SelectNodes("//table") te renvoie bien quelque chose ?
    (j'ai quelques doutes sur cette ligne du fait qu'il y ait peu de chance de trouver un élément table à la racine du XML)


    Salut jopopmk,

    Merci pour ta réponse, je n'arrive pas à charger la table dès le départ celle-ci n'a pas d' ID : <table> --- </table>

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    or Each tble As HtmlNode In doc.DocumentNode.SelectNodes("//table")

    Merci par avance.

  4. #4
    Membre Expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Par défaut
    Re,

    déjà j'ai dit une niaiserie dans mon premier post (un an sans xpath et j'ai déjà oublié comment ça marche ...).
    Pour ton souci je suis allé voir l'exemple fourni sur le codeplex de Html Agility Pack : ton code semble bon.
    Es-tu sûr que ton stream s'est bien chargé ? Que ton doc est bien monté ?

  5. #5
    Membre confirmé
    Inscrit en
    Mai 2010
    Messages
    62
    Détails du profil
    Informations forums :
    Inscription : Mai 2010
    Messages : 62
    Par défaut
    Citation Envoyé par jopopmk Voir le message
    Re,

    déjà j'ai dit une niaiserie dans mon premier post (un an sans xpath et j'ai déjà oublié comment ça marche ...).
    Pour ton souci je suis allé voir l'exemple fourni sur le codeplex de Html Agility Pack : ton code semble bon.
    Es-tu sûr que ton stream s'est bien chargé ? Que ton doc est bien monté ?
    Je viens de vérifier le document se charger bien.

    Maintenant quand je sélectionne mes balises <rr> j'ai l'erreur suivante :

    Une exception non gérée du type 'System.NullReferenceException' s'est produite dans WindowsApplication5.exe

    Déterminer si l'objet est nul avant de l'appeller !

  6. #6
    Membre Expert Avatar de jopopmk
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mars 2011
    Messages
    1 856
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2011
    Messages : 1 856
    Par défaut
    Ce bug est assez explicite : tu essaies d'accéder à un membre ou une méthode d'un objet qui n'est pas initialisé.
    Le plus souvent ça arrive quand on récupère un objet depuis une fonction qui ne nous renvoie rien mais qu'on tente quand même d'utiliser un membre ou une méthode de cet objet. Dans ton cas je pense que tu tentes d'utiliser l'objet retourné par SelectNodes(string) alors que celle-ci ne te renvoie rien (peut-être du fait que tu recherches "<rr>" qui n'est pas une balise standard du HTML -en tout cas pas à ma connaissance- et que donc il n'existe pas dans le document).

Discussions similaires

  1. Parser page HTML en java
    Par NGeVtC87 dans le forum Débuter avec Java
    Réponses: 11
    Dernier message: 04/03/2013, 09h57
  2. [PHP] Parser d'une page HTML pour récupération du texte
    Par trihanhcie dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 23
    Dernier message: 18/06/2011, 19h10
  3. Parser une page Html pour récuperer valeur
    Par Andry dans le forum Delphi
    Réponses: 5
    Dernier message: 01/12/2006, 17h10
  4. Parser une page html, quel outil ?
    Par ggnore dans le forum Linux
    Réponses: 5
    Dernier message: 28/11/2006, 11h48
  5. parser une page HTML pour en retirer de l'info
    Par belakhdarbts10 dans le forum ASP
    Réponses: 1
    Dernier message: 29/10/2006, 18h38

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo