Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27348

Regex Help

$
0
0
Hello everybody, im currently trying to make a small application that uses a search engine and gets all the links from the result. For example, if I were to go on bing, and search for "Gaming Websites", I would like to get a list of all the url's of each site and nothing more. Im not an expert with regex in anyway so if somebody could help me with this it would be much appreciated.


Here I have included a picture with afew results circled so you can see exactly what I am trying to retrieve from the site: http://puu.sh/1DWvs

Here is my code which for some reason is only returning about two results into my listbox:

Code:

    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("http://www.bing.com/search?q=" & TextBox1.Text)
        Dim response As System.Net.HttpWebResponse = request.GetResponse()
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
        Dim results As String = sr.ReadToEnd()
        Dim reg As New System.Text.RegularExpressions.Regex("href=""http://.*/.*?.*=.*"" h=""")
        Dim matches As MatchCollection = reg.Matches(results)
        For Each item As Match In matches
            ListBox1.Items.Add(item.Value.Split("""").GetValue(1))
        Next
        Using sr1 As New IO.StreamWriter("C:\ResultList.txt")
            For Each line In ListBox1.Items
                sr1.WriteLine(line)
            Next
            sr1.Close()
        End Using
    End Sub


Viewing all articles
Browse latest Browse all 27348

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>