Hi Brian
The following is a simple function I wrote in connection with the SOAP envelope I posted above (see my first post in this thread). There must be a better solution, but this does work just fine:
Function MSNAPIResults(gQuery, gAppID, gOffset) If Trim(gQuery) = "" Then Exit Function
Dim Qry Set Qry = Server.CreateObject("MSXML2.DOMDocument") Qry.load Server.MapPath("doMSNSearch.xml") Qry.selectSingleNode("//AppID").Text = gAppID Qry.selectSingleNode("//Query").Text = gQuery Qry.selectSingleNode("//Offset").Text = gOffset
' Post the SOAP message. Dim soap Set soap = Server.CreateObject("MSXML2.ServerXMLHTTP") soap.open "post", "http://soap.search.msn.com/webservices.asmx", False soap.setRequestHeader "Content-Type", "text/xml" soap.setRequestHeader "SOAPAction", "Search" soap.send Qry ' Dump the results into an XML document.
Dim Res Set Res = Server.CreateObject("MSXML2.DOMDocument") Res.loadXML (soap.responseText)
set root = Res.documentElement set nodelist = root.getElementsByTagName("Result")
' Parse the XML document. Dim rTitle Dim rDesc Dim rURL c = 0 Dim resArray ReDim resArray(49,2)
For Each Node In Nodelist 'retrieve the values rURL="" on error resume next rTitle = Node.childNodes.item(0).text rDesc = Node.childNodes.item(1).text rURL = Node.childNodes.item(2).text on error goto 0
if Trim(rURL)<>"" then 'its a result resArray(c, 0) = rTitle resArray(c, 1) = rDesc resArray(c, 2) = rURL c=c+1 End If Next MSNAPIResults = resArray End FUNCTION
I hope this helps?
By the way, we use this, along with some other very similar functions for the Google Search API, and Yahoo Search API (REST) in an online ranking checker application. The application isn't publicly available on our site as of course there's restrictions on how many automated queries you can run per day or month with an API key.
However, we've used very similar coding for our free keyword tool, and meta tag checker. You can find them on our services page if you wanted to have a look. Very simple tools indeed, but quite useful nonetheless. We use them constantly every day as we're a search engine optimisation company.
Let me know how you get on?
- Mark.
Search Engine Optimisation (SEO) Specialists: http://www.bsolveit.com |