我想从javascript创建的页面中提取表格,并且页面源中没有显示它的元素。这是页面(Link)。
在Firefox中,我可以通过"查看选择源"找到源的隐藏部分。但是VBA无法访问隐藏的元素:
Some (id 1) (id 2)
答案 0 :(得分:0)
试试这个。它应该获取您所追踪的表格数据:
Sub TableData()
Dim IE As New InternetExplorer, html As HTMLDocument
Dim post As Object, elem As Object, trow As Object
With IE
.Visible = False
.navigate "http://www.iafi.ir/%DA%AF%D8%B2%D8%A7%D8%B1%D8%B4%D8%A7%D8%AA/%D8%A7%D8%B1%D8%B2%D8%B4-%D8%AF%D8%A7%D8%B1%D8%A7%DB%8C%DB%8C-%D9%87%D8%A7-%D9%88-%D8%AA%D8%B9%D8%AF%D8%A7%D8%AF-%D9%88%D8%A7%D8%AD%D8%AF-%D9%87%D8%A7"
While .readyState < 4: DoEvents: Wend
Set html = .document
End With
Application.Wait Now + TimeValue("00:00:05") 'this is the trick here to get the data
Set post = html.getElementById("arzeshdarayi")
For Each elem In post.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
IE.Quit
End Sub
参考添加到库:
Microsoft Internet Controls
Microsoft HTML Object Library