shahin
Active Member
I've written a script to parse some information from a webpage. The information displayed multiple pages through pagination. I do not wish to hardcode the number of the last page but I expect the parser should still exhaust them all. This question has been erected many times in this forum. However, as every problem is different in nature from another so i thought to create a post.
Here is what I have tried (logic taken from one of Narayan's solution):
Html elements for next page:
Btw, the content traverses 3 pages.
Here is what I have tried (logic taken from one of Narayan's solution):
Code:
Sub Web_Data()
link$ = "https://info.bacb.com/o.php?page=100155&by=state&state=AL&pagenum="
Dim HTTP As New XMLHTTP60, HTML As New HTMLDocument
Dim posts As Object, elem As Object, trow As Object
Do
p = p + 1
With HTTP
.Open "GET", link & p, False
.send
HTML.body.innerHTML = .responseText
End With
Set posts = HTML.getElementsByTagName("table")(2)
For Each elem In posts.Rows
For Each trow In elem.Cells
c = c + 1: Cells(r + 1, c) = trow.innerText
Next trow
c = 0: r = r + 1
Next elem
Loop While InStr(HTTP.responseText, "<b>Next -></b>") > 0
End Sub
Html elements for next page:
Code:
<td colspan="6" bgcolor="#FFFFFF"><br>
<span class="paging"><b> -- Page 1 of 3 -- </b></span><p><span class="paging"> <a href="?page=100155&by=state&state=AL&pagenum=2"><b>Next -></b></a> </span> <span class="paging"> <a href="?page=100155&by=state&state=AL&pagenum=3">Last ->></a> </span>
</p></td>
Btw, the content traverses 3 pages.