2017-10-10 14 views
0

我有一個HTML文件,現在我從內部html獲得一個td我需要從我在我的html文件中找到的td中找到最接近的td值請有人幫我出這個如何使用vb.net從html獲得下一個(最近的)td的值

For Each item In itemlist 'look at each item in the collection 
          If item.Innerhtml = "Controller" Then 
           MsgBox(item.innertext) 'this would msgbox your description 
           Exit For 'exit once found 
          End If 

,你可以在代碼中看到我已經得到了具體的TD現在我需要衣櫃TD的價值,我不能做同樣的查找下一個TD因爲旁邊td不包含任何內部的html或id它只是包含值

回答

1

如果我沒有誤解你的問題:
你可以使用一個簡單的「for」,而不是「每個前」,當你找到合適的td時,得到下一個1。
例遞增索引:

For i As Integer = 0 To itemlist.Count 
    Dim item = itemlist.Item(i); 
    If item.Innerhtml = "Controller" Then 
    MsgBox(item.innertext) 
    Dim iNext = i++; 
    if iNext <= itemList.Count Then 
     Dim closestItem = itemList.Item(iNext) 
     'Do things 
    End If 
    Exit For 
    End If 
Next 
+0

三個注意事項:** 1)**你得環路'ITEMLIST .Count - 1「,否則它會在索引從零開始時超出範圍。 ** 2)**出於同樣的原因,您還必須將您的'If'語句更改爲:'如果iNext

+0

謝謝Daniele。 –

0
For Each item In itemlist 'look at each item in the collection 
          If item.Innerhtml = "Controller" Then 
           Controller = item.nextSibling.innertext.ToString.Trim 'this would save your description 
          End If 

我這是怎麼解決這個問題