page select in multipage web site

S

Stefi

Hi All,

I have a multipage web site, where
Set coursetables = IE.document.getElementsByTagname("table")
and after that
?coursetables.Item(16).Rows(0).Cells(0).innertext
returns

Page 1 of 2
Previous Page | Next Page

On the web page clicking manually on Next Page bring up the next page.

How can I find the object that can be clicked on in VBA (like clicking on a
button is done via myButton.click) to bring up the next page?

Thanks,
Stefi
 
J

Joel

I did a search on goolge to get a multi-page results and got this code. I
won't guarentee it will work in your case but it will give you an example. I
searched for the ID=nav to get the navigation object and then created a new
URL. I found that hoovering over the NEXT button showed the same results as
the NAV property.


Sub Macro3()
'

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://www.google.com/"
Search = "search?hl=en&q=joel&aq=f&oq=&aqi=g10"

Do
'get web page
IE.Navigate2 URL & Search
Do While IE.readyState <> 4 And IE.busy = True
DoEvents
Loop
'put you code here

Set Nextobj = IE.document.getElementByID("nav")
If Not Nextobj Is Nothing Then

Set NextPage = Nextobj.Cells(Nextobj.Cells.Length - 1)

Search = NextPage.FirstChild.nameprop

End If
Loop While Not Nextobj Is Nothing
End Sub
 
S

Stefi

Thanks to both of you, r and Joel, I'm going to follow the ways you showed
me. It's interesting that there is no simpler way for handling such an
everyday case!
Stefi


„Joel†ezt írta:
 
J

Joel

Here is some debug code you may need. The row where I put ID in column C may
need to be commented out because not all webpages support the property ID.
Look for the word Next in column D to help find the navigation object.


Sub Macro3()
'

Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

URL = "http://www.google.com/"
Search = "search?hl=en&q=joel&aq=f&oq=&aqi=g10"


'get web page
IE.Navigate2 URL & Search
Do While IE.readyState <> 4 And IE.busy = True
DoEvents
Loop
'put you code here
RowCount = 1
For Each itm In IE.document.all
Range("A" & RowCount) = itm.tagname
Range("B" & RowCount) = itm.classname
Range("C" & RowCount) = itm.ID
Range("D" & RowCount) = Left(itm.innertext, 1024)
RowCount = RowCount + 1
Next itm

Set Nextobj = IE.document.getElementByID("nav")
If Not Nextobj Is Nothing Then

Set NextPage = Nextobj.Cells(Nextobj.Cells.Length - 1)

Search = NextPage.FirstChild.nameprop

End If

End Sub
 
S

Stefi

Thanks, Joel! By the way, where can I find some description of these
web-handling statements (Navigate2, getElementByID, getElementByName, etc.)?
There is none in Excel VBA Help!
Stefi


„Stefi†ezt írta:
 
J

Joel

Do a search at microsoft.com for getElementByID

Stefi said:
Thanks, Joel! By the way, where can I find some description of these
web-handling statements (Navigate2, getElementByID, getElementByName, etc.)?
There is none in Excel VBA Help!
Stefi


„Stefi†ezt írta:
 
S

Stefi

Hi Joel,

I tried to follow the technique you suggested, but it failed at the website
I work on.
Set Nextobj = IE.document.getElementByID("nav")
returned Nothing because there was no "nav" element. Your debugging code
gave this result of the table rows in question:

A D
TABLE "Page 1 of 2
Previous Page | Next Page "
TBODY "Page 1 of 2
Previous Page | Next Page "
TR "Page 1 of 2
Previous Page | Next Page "
TD "Page 1 of 2
Previous Page | Next Page "
B Page 1 of 2
BR
SPAN Previous Page
A Next Page
B Next Page


(B,C are empty, in your example column C contained "nav")

The actual website is
URL = "http://schedule.msu.edu/"

I'm interested not in the content of this particular website but the paging
technique in such cases.

Thanks,
Stefi

„Joel†ezt írta:
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top