I am trying to retrieve table data from aspx page using excel vba.I know how to get table data from a URL but below is the main problem.
Problem
There is an aspx page (say www.abc.aspx). I am currently on this page.Let this page be page1.
Now I click a page2 link on the current page. What is worth noticing is that after clicking this link, the old URL (www.abc.aspx) doesn't change but the content changes.( Content is of page2 )
If you view page1 source code it has
<form method="post" action="page1 url" id="Form1">
Whatever is the action on page1 (page2 click) , it posts back the same page1 url.
So how can I get page2 table data in excel VBA since I don't know its URL?
Code
This is what I had used to fetch table data.
I used internet explorer object.Then navigated to the link and saved the document in htmldoc.
ie.navigate "url"
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Fetching data..."
DoEvents
Loop
Set htmldoc = ie.document
'Column headers
Set eleColth = htmldoc.getElementsByTagName("th")
j = 0 'start with the first value in the th collection
For Each eleCol In eleColth 'for each element in the td collection
ThisWorkbook.Sheets(1).Range("A1").Offset(i, j).Value = eleCol.innerText 'paste the inner text of the td element, and offset at the same time
j = j + 1 'move to next element in td collection
Next eleCol 'rinse and repeat
'Content
Set eleColtr = htmldoc.getElementsByTagName("tr")
'This section populates Excel
i = 0 'start with first value in tr collection
For Each eleRow In eleColtr 'for each element in the tr collection
Set eleColtd = htmldoc.getElementsByTagName("tr")(i).getElementsByTagName("td") 'get all the td elements in that specific tr
j = 0 'start with the first value in the td collection
For Each eleCol In eleColtd 'for each element in the td collection
ThisWorkbook.Sheets(1).Range("D3").Offset(i, j).Value = eleCol.innerText 'paste the inner text of the td element, and offset at the same time
j = j + 1 'move to next element in td collection
Next eleCol 'rinse and repeat
i = i + 1 'move to next element in td collection
Next eleRow 'rinse and repeat
ie.Quit
Set ie = Nothing
EDIT:
Example
If we click on questions in Stack Overflow (https://stackoverflow.com/questions) and now click on page2 of questions (new link is https://stackoverflow.com/questions?page=2&sort=newest)
In my case, if we click on page2, the new link is not updated.It is the same old link.
EDIT: I have found a similar question here
How do I get url that is hidden by javascript on external website?
Thanks.