Info Bea

Returning More Than One Page of Results

If you expect that a query will return more than one page of results,you can call the ImportXML query once for Page=i and again for Page=2.Note that on the second call, the Overwrite parameter for the ImportXML is set to False to add the results to the current list object.This code returns two pages of results for books published by Que in 2003:

Sub QuerybyPublisher() Dim ws As Worksheet Dim whr As New WinHttpRequest Dim lobj As ListObject Dim nCount As Integer Dim objSelected As Object

Dim sURI As String

Set objSelected = Selection Set ws = Worksheets("Sheet1") Set lobj = ws.ListObjects(l)

Application.Cursor = xlWait sURI = "http://xml.amazon.com/onca/xml2?t=webservices-20" _ & "&dev-t=D3VCCO47XZEQFA" _

& "&PowerSearch=publisher:Que and pubdate:2003" _ & "&mode=books&type=heavy&page=1&f=xml"

1 Get first 20 results whr.Open "GET", sURI whr.Send

ActiveWorkbook.XmlMaps(1).ImportXml whr.ResponseText, Overwrite:=True 1 Get next 20 results sURI = "http://xml.amazon.com/onca/xml2?t=webservices-20" _ & "&dev-t=D3VCCO47XZEQFA" _

& "&PowerSearch=publisher:Que and pubdate:2003" _ & "&mode=books&type=heavy&page=2&f=xml"

whr.Open "GET", sURI whr.Send

ActiveWorkbook.XmlMaps(1).ImportXml whr.ResponseText, Overwrite:=False Application.Cursor = xlDefault End Sub

The results are shown in Figure 15.9.

0 0

Post a comment