Google search in your site

Access to remote pages tutorial

Google allows at the moment and for learning porpoises to get access to their search engine and to get XML files with search results. In the script bellow this option is used to access that XML file and to extract from it the information we will latter display in our page (the way url, titles and snippet are extracted is a bit irregular).

This service from Google is for personal use and you must open a Google account to be able to use this service. They will provide you a Key you must include in the script . Extracting the same information from a regular google searchresults page is not legal.

Googlesearch.asp      Get code here
<html><head><title> Search</title></head>
<body bgcolor=ffffff>

if request.querystring="" then 

' You must ask Google for a key
key = "00000000000000000000000000000000000

' The URL where the script is located
URL = "http://www.yourdomain/yourscript.asp" 

SoapText = "<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV='' xmlns:xsi='' xmlns:xsd=''><SOAP-ENV:Body><ns1:doGoogleSearch xmlns:ns1='urn:GoogleSearch' SOAP-ENV:encodingStyle=''><key xsi:type='xsd:string'>" & key &"</key><q xsi:type='xsd:string'>" & request.querystring("keywords") & "</q><start xsi:type='xsd:int'>" & request.querystring("h") & "</start><maxResults xsi:type='xsd:int'>10</maxResults><filter xsi:type='xsd:boolean'>true</filter><restrict xsi:type='xsd:string'></restrict><safeSearch xsi:type='xsd:boolean'>false</safeSearch><lr xsi:type='xsd:string'></lr> <ie xsi:type='xsd:string'>latin1</ie><oe xsi:type='xsd:string'>latin1</oe></ns1:doGoogleSearch></SOAP-ENV:Body></SOAP-ENV:Envelope>"

Googleurl = "" 

Set objXML = CreateObject("Microsoft.XMLHTTP") "POST",Googleurl,"False"
objXML.setRequestHeader "Man", "POST" " " Googleurl " HTTP/1.1" 
objXML.setRequestHeader "MessageType", "CALL" 
objXML.setRequestHeader "Content-Type", "text/xml" 
objXML.send SoapText 

ResponsePage = objXML.responseText
Set objXML = Nothing

ResponsePage=Replace(ResponsePage," xsi:type=" & CHR(34) & "xsd:string" & CHR(34),"")

EstimatedResults=right(EstimatedResults,len (EstimatedResults)-inStr(EstimatedResults,"<estimatedTotalResultsCount")-46)
 Response.write ("Estimated results for <b>" & q & "</b>: " & EstimatedResults & " &nbsp; <A href=" & request.servervariables("URL") & "?keywords=" & request.querystring("keywords") & "&h=" & request.querystring("h")) 10 & "><font size=2>next 10</font></a><HR>")

public namearray
namearray=split (ResponsePage,"<item xsi:type=" & CHR(34) & "ns1:ResultElement" & CHR(34) & ">")

for i=1 to max

theurl=right(theurl,len (theurl)-instr(theurl,"<URL>")-4)

thetitle=right(thetitle,len (thetitle)-inStr(thetitle,"<title>")-6)
if thetitle="" then
thetitle="No Title"
end if

thedescription=right(thedescription,len (thedescription)-inStr(thedescription,"<snippet>")-8)

Searchresults=Searchresults & "<p><a href=" & theurl & ">" & thetitle & "</a><br>" & thedescription & "<br><font size=2>" & theurl & "</font>"



end if
<% Sub SendForm() %>

<form method=get action=<% =request.servervariables("URL") %>>
Find Keywords <input type=text name=keywords size=15>
 <input type=hidden name=h value=0> <input type=submit value="Google Search">

<% end sub%>
Script provided by <A HREF=></a>