Please help me.... See the code below.

Imports System.Text.RegularExpressions
Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("**HERE IS MY DESIRED URL**")
        Dim response As System.Net.HttpWebResponse = request.GetResponse

        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

        Dim rssourcecode As String = sr.ReadToEnd

        Dim r As New System.Text.RegularExpressions.Regex("<a class=""category"" href=""**HERE IS THE URL**"">**HERE SOME TEXt**</a><br /> ")
        Dim matches As MatchCollection = r.Matches(rssourcecode)
        For Each itemcode As Match In matches

        Next
    End Sub
End Class

I want to get data "HERE SOME TEXt" list in a combobox and respective "HERE IS THE URL" link in a textbox.

see as example 1
see as example 2

remember : in source code there have a lot of links. i want the link exack match as

<a class="category" href="link">name</a><br />

please help me....

You can try something like this:

Private CurrentCollection As HtmlElementCollection

Private Sub Populate(ByVal sAddress as String)
    'For example: sAddress = "www.google.com"
    Dim linkCollection As HtmlElementCollection = GetAllLinks(sAddress)

    For i = 0 To linkCollection.Count - 1
        ComboBox1.Items.Add(i)
    Next

    'Keep track of current links
    CurrentCollection = linkCollection
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    Try
        If ComboBox1.SelectedValue < CurrentCollection.Count - 1 Then
            'Fill the Text Box
            TextBox1.Text = CurrentCollection.Item(CInt(ComboBox1.SelectedValue)).OuterText
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub


Private Function GetAllLinks(ByVal sDocument As String) As HtmlElementCollection
    Try
        Dim bLoad As New WebBrowser()
        bLoad.Navigate(sDocument)

        While bLoad.ReadyState <> WebBrowserReadyState.Complete
            'Loop till loaded.
        End While

        Dim htmlDoc As HtmlDocument = bLoad.Document

        'Return the Collection
        Return htmlDoc.Links
    Catch ex As Exception
        MsgBox(ex.ToString)
        Return Nothing
    End Try
End Function

hey Begginnerdev: Thanks for your help. But sorry to say, some problem in your code...

I added :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call GetAllLinks()
    End Sub

but it gave me an error in "sDocument".

Will you tell me the full code starting like:

Public Class Form1
..
...
...
....
.....
......
End Class

**after adding your code, my code is as below:
**

Imports System.Text.RegularExpressions

Public Class Form1

    Private CurrentCollection As HtmlElementCollection

    Private Sub Populate(ByVal sAddress As String)
        sAddress = "http://google.com"
        Dim linkCollection As HtmlElementCollection = GetAllLinks(sAddress)

        For i = 0 To linkCollection.Count - 1
            ComboBox1.Items.Add(i)
        Next

        'Keep track of current links
        CurrentCollection = linkCollection
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles ComboBox1.SelectedIndexChanged
        Try
            If ComboBox1.SelectedValue < CurrentCollection.Count - 1 Then
                'Fill the Text Box
                TextBox1.Text = CurrentCollection.Item(CInt(ComboBox1.SelectedValue)).OuterText
            End If
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
    End Sub


    Private Function GetAllLinks(ByVal sDocument As String) As HtmlElementCollection
        Try
            Dim bLoad As New WebBrowser()
            bLoad.Navigate("sDocument")

            While bLoad.ReadyState <> WebBrowserReadyState.Complete
                'Loop till loaded.
            End While

            Dim htmlDoc As HtmlDocument = bLoad.Document

            'Return the Collection
            Return htmlDoc.Links
        Catch ex As Exception
            MsgBox(ex.ToString)
            Return Nothing
        End Try
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call GetAllLinks()
    End Sub
End Class

Please upload a full sourcecode as attachment. i am using Visual basic 2010

If you look closely in the code, the function GetAllLinks takes a parameter called sDocument.

The function is just a data retreival method, you should call Populate for your combobox.

For example:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Populate("www.google.com")
    End Sub
End Class

after editing as you said (Begginnerdev) when i am clicking button 1 then the application hangs, cursor turned into busy mood and hangs me a lot of time. then i closed the apps.
I tried a lot but every time getting this.
please do something.....

You need to step through and see if the browser is not loading the document.

This code:

   While bLoad.ReadyState <> WebBrowserReadyState.Complete
       'Loop till loaded
   End While

Could be changed to this:

 While bLoad.ReadyState < 3
            'Loop till loaded.
 End While

This will loop until the browser has the ability to "see" the page contents.

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.