ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

 Top ASP 101 Stories Top ASP 101 Stories
VBScript Classes: Part 1 of N
Migrating to ASP.NET
Getting Scripts to Run on a Schedule

The QueryString Has a Maximum Length
Show All Tips >>
ASP 101 RSS Feed ASP 101 Updates

Working with Google APIs to Fetch Results using ASP

by Vishal Parikh (a.k.a Graphiz)


Google is experimenting with a free web service that can be used non-commercially to gather search results in XML format. This format allows the search results to be displayed in any way the user wishes or transformed into another format. The interface is currently limited to returning only 10 results.

ASP Script

Below is an ASP script which has a very simple form which takes a input string from user, queries the Google search engine and return first 10 results and displays the results as simple links on the page. You can modify this script to perform other tasks once the results are returned.

Code / Script

The following ASP script block creates the SOAP message that queries the Google API, posts it to the Google web service ( using its search method (doGoogleSearch), places the result in an XML document and parses the document, extracting the page title and URL of each item returned by the query. You implement this by placing the script anywhere between the body tags of your ASP page and modifying the line Google_Web_APIs_license_key = "00000000000000000000000000000000000" by changing the zeros to your actual license key (obtained from Google) and your desired search string.

<title>Google at its best... Graphiz Design </title>
If Request.Form("SubmitButton") <> "Submit" Then
  <form method="post" name="g" action="google.asp">
  <input type="text" name="searchstring" size="20"><br>
  <input type="submit" value="Submit" name="SubmitButton">
  Results for Google Search:
  <font color="red"><%=request.form("searchstring")%></font>
  Google_Web_APIs_license_key = "00000000000000000000000000000000"
  If Request.Form("searchstring") = "" Then
    Search_String = "Sample Search"
    Search_String = Request.Form("searchstring")
  End If
  ' This SOAP message came from the Google API soap-examples.
  ' Dump the SOAP message into an XML document and set the key value,
  ' search string value and start index.
  Set objInputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
  objInputXMLDoc.load Server.MapPath("doGoogleSearch.xml")
  objInputXMLDoc.selectSingleNode("//key").Text = Google_Web_APIs_license_key
  objInputXMLDoc.selectSingleNode("//q").Text = Search_String
  objInputXMLDoc.selectSingleNode("//start").Text = 0
  ' Post the SOAP message.
  Set objXMLHTTP = Server.CreateObject("Microsoft.XMLHTTP") "post", "", False
  objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
  objXMLHTTP.setRequestHeader "SOAPAction", "doGoogleSearch"
  objXMLHTTP.send objInputXMLDoc
  ' Dump the results into an XML document.
  Set objOutputXMLDoc = Server.CreateObject("Microsoft.XMLDOM")
  objOutputXMLDoc.loadXML objXMLHTTP.responseText
  ' Parse the XML document.
  Set Nodes = objOutputXMLDoc.selectNodes("//item")
  For Each Node In Nodes
    Response.Write "<a href=""" & Node.selectSingleNode("URL").Text & """>" _
      & Node.selectSingleNode("title").Text & "</a><br>" & VbCrLf
End If
Function showXML(XMLSource)
  Response.Write XMLSource
End Function

Happy Programming
Prays for all


Related Articles

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers