从不在源代码中的网页中提取数据

时间:2015-06-19 15:23:46

标签: javascript excel dom vbscript

我想在Excel中编写一个宏来从下面的网页中提取数据:

http://www.richmond.com/data-center/salaries-virginia-state-employees-2013/?appSession=673718284851033&RecordID=101177&PageID=3&PrevPageID=2&cpipage=1&CPIsortType=&CPIorderBy=&cbCurrentRecordPosition=1

我遇到的问题是员工信息数据不在页面源中,因此当我使用下面的代码(其中NextPage设置为上述URL)时,responseText不包括数据我正在寻找。

With CreateObject("msxml2.xmlhttp")
    .Open "GET", NextPage, False
    .Send
    htm.body.innerHtml = .responseText
End With

我很可能错了,但我相信数据包含在页面的DOM中。有人可以帮我理解如何使用VBScript下载所显示的页面内容(即在应用了javascript修改之后)吗?

1 个答案:

答案 0 :(得分:0)

使用InternetExplorer.Application COM对象可以访问实际的DOM树:

url = "http://www.richmond.com/..."

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

ie.Navigate url

Do
  WScript.Sleep 100
Until ie.ReadyState = 4

Set elem = ie.Document.getElementById("...")

如果这不起作用,您可能不得不求助于PhantomJS

相关问题