使用Excel VBA从aspx页面表中检索数据

use*_*632 5 asp.net excel vba http excel-vba

我正在尝试使用excel vba 从aspx页面检索表数据.我知道如何从URL获取表数据但下面是主要问题.

问题

有一个aspx页面(比如www.abc.aspx).我目前在此页面.请将此页面设为page1.

现在,我单击当前页面上的page2链接.什么是值得注意的是,点击该链接后,旧的URL(www.abc.aspx)不会改变,但内容的变化.(内容是第2页)

如果您查看它的page1源代码

<form method="post" action="page1 url" id="Form1">
Run Code Online (Sandbox Code Playgroud)

无论第1 (第2页点击)操作是什么,它都会回发相同的page1网址.

那么如何在excel VBA中获取page2 数据,因为我不知道它的URL?

这就是我用来获取表数据的方法.

我使用了Internet Explorer对象.然后导航到链接并将文档保存在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
Run Code Online (Sandbox Code Playgroud)

编辑:

如果我们点击的堆栈溢出问题(https://stackoverflow.com/questions)和现在的问题,第2页点击(新链接https://stackoverflow.com/questions页= 2&排序=最新)

在我的情况下,如果我们点击第二页,新的链接不updated.It是一样的旧的链接.

编辑:我在这里找到了类似的问题

如何在外部网站上获取javascript隐藏的网址?

谢谢.