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
VBScript Classes: Part 1 of N
Migrating to ASP.NET
Getting Scripts to Run on a Schedule

QUICK TIP:
Using " in your Strings
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)

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

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

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES