2017-08-16 1 views
0

Condition: extraire le texte "Lossless".Utilisation de HtmlAgility pour extraire du texte à l'intérieur d'une plage

<td nowrap="nowrap" align="center"> 
<span class="gen">4:59<br /><span style="color: red">Lossless</span></span> 
</td> 

Je ne pouvais extraire le texte entier "4: 59Lossless" de par:

Dim divnodes As HtmlNode = doc.DocumentNode.SelectSingleNode("//td[@nowrap='nowrap']//span[@class='gen']") 

     If Not divnodes Is Nothing Then 
      MsgBox(div.InnerText) 
     End If 

J'ai aussi essayé

Msgbox(div.Attributes("style").Value) 

mais pas de travail.

Pourriez-vous m'adresser. Merci ~

Répondre

0

Je l'ai résolu en ajoutant "/ span"

  Dim divnodes As HtmlNodeCollection =doc.DocumentNode.SelectNodes("//td[@nowrap='nowrap']//span[@class='gen']/span") 

      If divnodes IsNot Nothing Then 
      For each div as HtmlNode in divnodes2 
       MsgBox(div.InnerText) 
      Next    
      End If 
+1

Soit dit en passant, vous pouvez utiliser 'Si divnodes IsNot Rien Then' au lieu, comme recommandé dans [Conventions de codage Visual Basic] Microsoft (https://docs.microsoft.com/en-us/dotnet/visual-basic/programming-guide/program-structure/coding-conventions). –

+0

Merci @AndrewMorton pour le lien utile. Ouais. Ils suggèrent d'utiliser "IsNot" au lieu de "Not ... Is". Réponse mise à jour! –