I would do it using regex:
Import the following:
Imports System.Text.RegularExpressions
Declare the following variables:
Dim text1 As String = ""
Dim text2 As String = ""
Dim text3 As String = "</option>"
Dim SelectId As String = "ctl00_ctl00_Content_contentMain_Home1_ReportFilter_drpGroup" 'Change to the Select element ID
Remember to change the SelectId variable to the select ID
Add the following function:
Public Sub Process()
Dim txt As String = text1
Dim re1 As String = "(<OPTION)"
Dim re2 As String = ".*?"
Dim re3 As String = "(<\/OPTION>)"
Dim r1 As Regex = New Regex(re1 + re2 + re3, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
Dim m1 As Match = r1.Match(txt)
If (m1.Success) Then
text2 = m1.ToString
text1 = text1.Replace(m1.ToString, "")
End If
Dim txt2 As String = text2
Dim re4 As String = "(>)"
Dim re5 As String = ".*?"
Dim re6 As String = "(<)"
Dim r2 As Regex = New Regex(re4 + re5 + re6, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
Dim m2 As Match = r2.Match(txt2)
If (m2.Success) Then
Dim optionValue As String = m2.ToString.Replace(">", "")
optionValue = optionValue.Replace("<", "")
If optionValue = text3 Then
Exit Sub
Else
text3 = optionValue
TextBox1.Text &= optionValue & Environment.NewLine
'Or ListBox1.Items.Add(optionValue)
Process()
End If
End If
End Sub
Now lets say you have a button that when you click it will list the options value in TextBox1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim txt As String = WebBrowser1.Document.Body.OuterHtml
Dim re2 As String = "(id)"
Dim re3 As String = "(=)"
Dim re4 As String = "(" & SelectId & ")"
Dim re5 As String = ".*?"
Dim re8 As String = "(<\/SELECT>)"
Dim r As Regex = New Regex(re2 + re3 + re4 + re5 + re8, RegexOptions.IgnoreCase Or RegexOptions.Singleline)
Dim m As Match = r.Match(txt)
If (m.Success) Then
text1 = m.ToString
End If
Process()
End Sub
It worked with me!! Try and let me know. My source: visual basic tutorials