shahin
Active Member
I've written a macro to get the highest "next page" number from a webpage traversing several pages. My target is to get the highest "next page" number from page 64, 65 and 66. Each individual page has displayed it's items across several pages through pagination. Page 64 has 3 such sub pages, page 66 has also 3 such pages but 65 doesn't have any pagination at all. So , my code breaks when the loop hits the page 65. How can I create any conditional statement to bypass or skip the page with no such pagination?
This is what I've written so far:
This is what I've written so far:
Code:
Sub Web_Data()
Dim http As New XMLHTTP60, html As New HTMLDocument
Dim elem As Object
For x = 64 To 66
With http
.Open "GET", "http://www.pour-les-personnes-agees.gouv.fr/annuaire-accueil-de-jour/" & x & "/0", False
.send
html.body.innerHTML = .responseText
End With
Set elem = html.getElementsByClassName("next last")(0).getElementsByTagName("a")
r = r + 1: Cells(r, 1) = Split(elem(0).href, "=")(1)
Next x
End Sub