The Code
Save the following code to a text file called
googly.vb:
' googly.vb
' A Google Web API VB.NET console application.
' Usage: googly.exe <query>
' Copyright (c) 2002, Chris Sells.
' No warranties extended. Use at your own risk.
Imports System
Module Googly
Sub Main(ByVal args As String( ))
' Your Google API developer's key.
Dim googleKey As String = "insert key here"
' Take the query from the command line.
If args.Length <> 1 Then
Console.WriteLine("Usage: google.exe <query>")
Return
End If
Dim query As String = args(0)
' Create a Google SOAP client proxy, generated by:
' c:\> wsdl.exe /l:vb http://api.google.com/GoogleSearch.wsdl
Dim googleSearch As GoogleSearchService = New GoogleSearchService( )
' Query Google.
Dim results As GoogleSearchResult = googleSearch.
doGoogleSearch(googleKey, query, 0, 10, False, "", False, "", "latin1",
"latin1")
' No results?
If results.resultElements Is Nothing Then Return
' Loop through results.
Dim result As ResultElement
For Each result In results.resultElements
Console.WriteLine( )
Console.WriteLine(result.title)
Console.WriteLine(result.URL)
Console.WriteLine(result.snippet)
Console.WriteLine( )
Next
End Sub
End Module
You'll need to replace insert key
here with your Google API key.
Your code should look something like this:
' Your Google API developer's key.
Dim googleKey As String = "12BuCK13mY5h0E/34KN0cK@ttH3Do0R
"