【问题标题】:Excel VBA - Referencing HTML <div> AttributesExcel VBA - 引用 HTML <div> 属性
【发布时间】: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


    【解决方案1】:

    试试:

    Debug.Print objCollection(i).getAttribute("data-full-name")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-09
      • 2019-11-17
      • 1970-01-01
      • 2019-02-14
      • 1970-01-01
      相关资源
      最近更新 更多