简体   繁体   中英

how to get value of next (Closest) td from html using vb.net

I have a HTML file and I get a td from inner html now I need to find closest td value from the td that I found in my html file please some one help me out of this

    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

you can see in code I have get the specific td now I need to get the value of closet td, I can't do the same to find next td because next td does not contains any inner html or id its just contains value

If i haven't misunderstood your question:
You could use a simple "for" instead a "fore each" and, when you find the right td, get the next one incrementing the index by 1.
Example:

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
   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

this is how I resolve the issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM