【发布时间】:2021-05-06 09:59:21
【问题描述】:
我在 Excel VBA 中使用下面提到的代码进行 IE 导航。从 iframe 获取数据时遇到以下错误。
错误详情:
对象不支持该属性或方法
Option Explicit
Public Sub Cgg_Click()
Dim Ie As New InternetExplorer
Dim WebURL
Dim Docx As HTMLDocument
Dim productDesc
Dim productTitle
Dim price
Dim RcdNum
Ie.Visible = True
WebURL = "https://www.google.com/maps/place/parlour+beauty+parlour+beauty/@40.7314166,-74.13182,11z/data=!4m8!1m2!2m1!1sParlour+NY!3m4!1s0x89c2599bd4c1d2e7:0x20873676f6334189!8m2!3d40.7314166!4d-73.9917443"
Ie.Navigate2 WebURL
Do Until Ie.readyState = READYSTATE_COMPLETE
DoEvents
Loop
Application.Wait (Now + TimeValue("00:00:25"))
For N = 0 To Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Length - 1
If Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).innerText = "Web results" Then
Ie.document.getElementsByClassName("section-subheader-header GLOBAL__gm2-subtitle-alt-1").Item(N).ScrollIntoView (False)
End If
Next N
Application.Wait (Now + TimeValue("00:00:25"))
Set Docx = Ie.document
productDesc = Docx.Window.frames("section-iframe-iframe").contentWindow.document.getElementsByClassName("trex")(0).outerHTML
End Sub
这是 HTML:
请帮助解决此错误。
我想从上面的 url 中提取 "trex" ClassName HTML Contain
谢谢。
【问题讨论】:
-
直接导航到iframe的src
-
请通过edit使用sn-p工具插入html而不是张贴html图片。我们无法从该图像复制粘贴。请参阅this 以获取帮助或使用请参阅help center 的格式部分。使用 iframe 的 src 导航请参阅:stackoverflow.com/questions/44902558/…
标签: html vba internet-explorer web-scraping iframe