【发布时间】:2018-06-14 17:27:00
【问题描述】:
我几天来一直在努力编写一些代码,以从网页源代码中输出“数据全名”的值(链接到下面的屏幕截图)。
我知道我可以使用 objCollection(i).className 访问实例的“类”的值,但是如何访问其他 div 属性?
谢谢!
网页源代码截图
Private Sub Extract_Info()
Dim i As Long
Dim ie As Object
Dim objElement As Object
Dim objCollection As Object
' Create InternetExplorer Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = False
ie.navigate "http://mywebpage.com.au/"
' Wait while IE loading...
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
'Begin extraction
Set objCollection = ie.document.getElementsByTagName("div")
i = 0
While i < objCollection.Length
If objCollection(i).ClassName = "listing listing-search listing-data" Then
'Not sure how to code here:
e.g. MsgBox (objCollection(i).data-full-name)
End If
i = i + 1
Wend
End Sub
【问题讨论】:
标签: vba excel internet-explorer