How to Create a Quick Bing Searcher in Visual Basic
Submitted by Yorkiebar on Monday, October 14, 2013 - 06:01.
Language
Introduction:
Welcome to my tutorial on how to create a quick bing searcher in visual basic. It will search a given query and launch the first three links.
Steps of Creation:
Step 1:
First we want to import some namespaces and create a function get a list of strings between two points within a given string...
Step 2:
Now we want to initialize the search query. We must replace any spaces with a plus symbol in order for it to work properly in the url.
Step 3:
Now we want to go to the search query page and retrieve the source code. We then want to extract all the links within the page.
Step 4:
Now we want to run through all the links and add the first three that are stand alone links (http://) to a new list. We then want to run them all.
Project Complete!
Below is the full source code and download to the project files.
- Imports System.Text.RegularExpressions
- Imports System.Net
- Imports System.IO
- Private Function GetBetweenAll(ByVal Source As String, ByVal Str1 As String, ByVal Str2 As String) As String()
- Dim Results, T As New List(Of String)
- T.AddRange(Regex.Split(Source, Str1))
- T.RemoveAt(0)
- For Each I As String In T
- Results.Add(Regex.Split(I, Str2)(0))
- Next
- Return Results.ToArray
- End Function
- Dim q As String = TextBox1.Text
- If (q.Contains(" ")) Then q.Replace(" ", "+")
- Dim link As String = "http://www.bing.com/search?q=" & q & "&go=&qs=bs&form=QBLH&filt=all"
- Dim r As HttpWebRequest = HttpWebRequest.Create(link)
- Dim re As HttpWebResponse = r.GetResponse()
- Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
- Dim links As String() = GetBetweenAll(src, "<h3><a href=""", """")
- Dim urls As New List(Of String)
- Dim i As Integer = 0
- Do Until urls.Count() >= 3
- If (links(i).StartsWith("http://")) Then urls.Add(links(i))
- i += 1
- Loop
- For Each u As String In urls
- Diagnostics.Process.Start(u)
- Next
- Imports System.Text.RegularExpressions
- Imports System.Net
- Imports System.IO
- Public Class Form1
- Private Function GetBetweenAll(ByVal Source As String, ByVal Str1 As String, ByVal Str2 As String) As String()
- Dim Results, T As New List(Of String)
- T.AddRange(Regex.Split(Source, Str1))
- T.RemoveAt(0)
- For Each I As String In T
- Results.Add(Regex.Split(I, Str2)(0))
- Next
- Return Results.ToArray
- End Function
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Dim q As String = TextBox1.Text
- If (q.Contains(" ")) Then q.Replace(" ", "+")
- Dim link As String = "http://www.bing.com/search?q=" & q & "&go=&qs=bs&form=QBLH&filt=all"
- Dim r As HttpWebRequest = HttpWebRequest.Create(link)
- Dim re As HttpWebResponse = r.GetResponse()
- Dim src As String = New StreamReader(re.GetResponseStream()).ReadToEnd()
- Dim links As String() = GetBetweenAll(src, "<h3><a href=""", """")
- Dim urls As New List(Of String)
- Dim i As Integer = 0
- Do Until urls.Count() >= 3
- If (links(i).StartsWith("http://")) Then urls.Add(links(i))
- i += 1
- Loop
- For Each u As String In urls
- Diagnostics.Process.Start(u)
- Next
- End Sub
- End Class
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Add new comment
- 108 views