'LucidDevelopment (March 20, 2013 - 21:43)
'!NO CREDITS REQUIRED! The code is mine and I give you all the permission to use without credits given.
Function GetURLs(query As String) As List(Of String)
Dim rtn As New List(Of String)
Dim rgxSection As New System.Text.RegularExpressions.Regex("
(?- .*?)
")
Dim hrefRgx As New System.Text.RegularExpressions.Regex("(?:(?:http|https):\/\/)?([-a-zA-Z0-9.]{2,256}\.[a-z]{2,4})\b(?:\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?")
Try
Dim section As System.Text.RegularExpressions.MatchCollection = rgxSection.Matches((New System.Net.WebClient()).DownloadString(New Uri("http://www.google.com/search?q=" & query)))
For Each m1 As System.Text.RegularExpressions.Match In section
Dim url As System.Text.RegularExpressions.MatchCollection = hrefRgx.Matches(m1.Groups("item").Value)
For Each m2 As System.Text.RegularExpressions.Match In url
rtn.Add(m2.Value.Replace("%3F", "?").Replace("%3D", "=").Replace("&", ""))
'Simply cleaning up the URL and making it readable.
Next
Next
Catch ex As Exception
MessageBox.Show(ex.ToString & vbNewLine & vbNewLine & "GetURLs(...) - LucidDevelopment")
End Try
Return rtn
End Function
'Usage
Dim item As List(Of String) = GetURLs(TextBox1.Text)
For Each s As String In item
'"s" is the URL. Do something with it <3
Next
///////////////////////////C#////////////////////////////////////