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

Please visit our partners

Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash


 Top ASP 101 Stories Top ASP 101 Stories
What is Adovbs.inc and Why Do I Need It?
An Overview of ASP.NET
Connections, Commands, And Procedures

QUICK TIP:
Reduce Web Form Spam by Checking Server Variables
Show All Tips >>


Working with Google APIs to Fetch Results using ASP

by Vishal Parikh (a.k.a Graphiz)

Introduction

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 (http://api.google.com/search/beta2) 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.

google.asp

<html>
<head>
<title>Google at its best... Graphiz Design </title>
</head>
<body>
<%
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">
  <form>
  <%
Else
  %>
  <p>
  Results for Google Search:
  <font color="red"><%=request.form("searchstring")%></font>
  </p>
  <%
  Google_Web_APIs_license_key = "00000000000000000000000000000000"
  
  If Request.Form("searchstring") = "" Then
    Search_String = "Sample Search"
  Else
    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")
  objXMLHTTP.open "post", "http://api.google.com/search/beta2", False
  objXMLHTTP.setRequestHeader "Content-Type", "text/xml"
  objXMLHTTP.setRequestHeader "SOAPAction", "doGoogleSearch"
  objXMLHTTP.send objInputXMLDoc
  'showXML(objXMLHTTP.responseText)
  '
  ' 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
  Next
End If
%>
</body>
</html>
<%
Function showXML(XMLSource)
  Response.Clear
  Response.Write XMLSource
  Response.End
End Function
%>

Happy Programming
Prays for all

Graphiz

Related Articles


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
IBM eBook: Planning a Service Oriented Architecture
IBM eBook: Choosing the Right Architecture--What It Means for You and Your Business
Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
Avaya Article: Using Intelligent Presence to Create Smarter Business Applications
Intel Go Parallel Article: Getting Started with TBB on Windows
Microsoft Article: 7.0, Microsoft's Lucky Version?
Avaya Article: How to Feed Data into the Avaya Event Processor
IBM Article: Developing a Software Policy for Your Organization
Microsoft Article: Managing Virtual Machines with Microsoft System Center
Intel Go Parallel Article: Intel Threading Tools and OpenMP
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
HP Video: StorageWorks EVA4400 and Oracle
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Red Gate Download: SQL Toolbelt and free High-Performance SQL Code eBook
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
Silverlight 2 App and Walkthrough: Leverage Silverlight 2 with SQL Server and XML
IBM Article: Enterprise Search--Do You Know What's Out There?
HP Demo: StorageWorks EVA4400
Microsoft Article: The Progress and Promise of Deep Zoom
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES