Hi Guys

Can anyone give me an example on how to retrieve the value 16 in bold under the tagname <td>In process</td> with a webbrowser and insert this value to a texbox. Thanks

<tbody>
<tr class="odd">
<td>In Process</td>
<td class="number">***16***</td>
<td class="number">1</td>
<td class="number">01:16:48</td>
<td class="number">02:54:00</td>
<td class="radio"><input type="radio" name="queue" checked="checked" onclick="document.location.href='management.lhtml?queue=1';" /></td>
</tr>
<tr>
<td>Verification</td>
<td class="number">11</td>
<td class="number">0</td>
<td class="number">00:59:24</td>
<td class="number">07:23:26</td>
<td class="radio"><input type="radio" name="queue" onclick="document.location.href='management.lhtml?queue=2';" /></td>
</tr>
<tr class="odd">
<td>Ready</td>
<td class="number">20</td>
<td class="number">0</td>
<td class="number">03:26:40</td>
<td class="number">08:38:42</td>
<td class="radio"><input type="radio" name="queue" onclick="document.location.href='management.lhtml?queue=3';" /></td>
</tr>

To retrieve the value there must be a pattern that can be implemented, let us assume that the pattern is as follows.

  1. There is only one table row with where the first child element has it's innner text equal to "In Process".
  2. The "In Process" element has at least one sibling and it can be parsed as a number.

Essentially, for this to work reliably, the HTML must be layedout like you have shown. Using these constraints, it is possible to construct a query of the document to attempt to retrieve a number. Additional constrainst could be imposed, but I'll leave that to you.

The following code demonstrates how to query a webbrowser's document and attempt to return a number based on the constraints defined above.

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

     Dim value As Single
     If GetMyValue(wb1, value) Then
        MsgBox("the value is: " & value.ToString)
     Else
        MsgBox("could not retrieve value")
     End If


  End Sub

  Private Function GetMyValue(ByVal wb As WebBrowser, ByRef value As Single) As Boolean
     If wb.Document Is Nothing Then Return False 'no point in going any further

     Dim rows As List(Of HtmlElement) = (From tr In wb.Document.GetElementsByTagName("TR") Select tr Where CType(tr, HtmlElement).FirstChild.InnerText = "In Process").Cast(Of HtmlElement).ToList
     If rows.Count = 1 Then
        Dim firstElementAfterInProcess As HtmlElement = rows(0).FirstChild.NextSibling

        If firstElementAfterInProcess IsNot Nothing Then
           Try
              value = Single.Parse(firstElementAfterInProcess.InnerText)
              Return True
           Catch ex As Exception
              'could not parse a value
              Return False
           End Try
        Else
           Return False

        End If 'firstElementAfterInProcess IsNot Nothing
     Else
        Return False
     End If ' rows.Count = 1

  End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.