Forum Moderators: open
Ok, with that out of the way ....
I am trying to use a sample code base I found to utilize the Google API for pulling in results. Here's the code ...
<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 = "00000000"
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.load "C:\Inetpub\wwwroot\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 "Node found! <br>"
Response.Write "<a href=""" & Node.selectSingleNode("URL").Text & """>" & Node.selectSingleNode("title").Text & "</a><br>" & VbCrLf
Next End If
Function showXML(XMLSource)
Response.Clear
Response.Write XMLSource
Response.End
End Function
%>
</body>
</html>
Ok, first off -- you'd need a Google API key to use this, it won't run as-is. And then a "search string". Let's say I'm using iPod as an example.
Next, you'd need doGoogleSearch.xml, which I have pasted here (also requires Google API key):
<?xml version='1.0' encoding='UTF-8'?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:doGoogleSearch xmlns:ns1="urn:GoogleSearch"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<key xsi:type="xsd:string">0000000000000</key>
<q xsi:type="xsd:string">shrdlu winograd maclisp teletype</q>
<start xsi:type="xsd:int">0</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>
So here's the fun part. The code runs. And it even gets a response from Google. But the code crashes on trying to output "Node.selectSingleNode("URL").Text" with the following error:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'Node.selectSingleNode(...)'
/google.asp, line 60
Now - how do I know my code works? If I comment out the existing response.write line ... and uncomment the "Node found!" line, I get 10 instances of that ... which matches up perfectly with the fact that Google will only return 10 results as a part of their API.
In addition, if I uncomment the "showXML(objXMLHTTP.responseText)" line, it gives me a bit of a debug view and then stops. Looking at the results, I'm seeing the following (I've snipped items 2-10):
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Body>
<ns1:doGoogleSearchResponse xmlns:ns1="urn:GoogleSearch" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<return xsi:type="ns1:GoogleSearchResult">
<directoryCategories xmlns:ns2="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Array" ns2:arrayType="ns1:DirectoryCategory[1]">
<item xsi:type="ns1:DirectoryCategory">
<fullViewableName xsi:type="xsd:string">Top/Computers/Hardware/Peripherals/Audio/Portable_Players/Apple_iPod</fullViewableName>
<specialEncoding xsi:type="xsd:string"></specialEncoding>
</item>
</directoryCategories>
<documentFiltering xsi:type="xsd:boolean">true</documentFiltering>
<endIndex xsi:type="xsd:int">10</endIndex>
<estimateIsExact xsi:type="xsd:boolean">false</estimateIsExact>
<estimatedTotalResultsCount xsi:type="xsd:int">592000000</estimatedTotalResultsCount>
<resultElements xmlns:ns3="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Array" ns3:arrayType="ns1:ResultElement[10]">
<item xsi:type="ns1:ResultElement">
<URL xsi:type="xsd:string">http://www.apple.com/ipod/</URL>
<cachedSize xsi:type="xsd:string">11k</cachedSize>
<directoryCategory xsi:type="ns1:DirectoryCategory">
<fullViewableName xsi:type="xsd:string"></fullViewableName>
<specialEncoding xsi:type="xsd:string"></specialEncoding>
</directoryCategory>
<directoryTitle xsi:type="xsd:string"></directoryTitle>
<hostName xsi:type="xsd:string"></hostName>
<relatedInformationPresent xsi:type="xsd:boolean">true</relatedInformationPresent>
<snippet xsi:type="xsd:string">Complete line of flash memory and hard drive-based music, video, and media content<br> players. Includes...</snippet>
<summary xsi:type="xsd:string"></summary>
<title xsi:type="xsd:string">Apple: <b>iPod</b></title>
</item>
</resultElements>
<searchComments xsi:type="xsd:string"></searchComments>
<searchQuery xsi:type="xsd:string">iPod</searchQuery>
<searchTime xsi:type="xsd:double">0.083884</searchTime>
<searchTips xsi:type="xsd:string"></searchTips>
<startIndex xsi:type="xsd:int">1</startIndex>
</return>
</ns1:doGoogleSearchResponse></SOAP-ENV:Body>
</SOAP-ENV:Envelope>
So, I'm getting results. They're in XML. And existing code that's been posted in a lot of places on the web should be helping me parse those values out. But I'm banging my head against my desk here trying to figure out why it doesn't like going after the attributes.
Totally boggled ...
Thanks in advance for any help!