【发布时间】:2017-10-18 15:19:14
【问题描述】:
我想创建一些 VBA 来从网站中提取信息。我在 HTML 中找到了这些信息,但我相信只有在页面上单击某些按钮时才会在 HTML 源代码中显示/填充它。我一直在尝试使用 getElementsByTagName 来执行点击,但到目前为止还没有奏效。到目前为止,我的代码是立即尝试第二次点击:
Sub googlesearch()
Set objIE = CreateObject("InternetExplorer.Application")
WebSite = "MyLink"
With objIE
.Visible = True
.navigate WebSite
Do While .Busy Or .readyState <> 4
DoEvents
Loop
Set elems = .getElementsByTagName("button")
For Each e In elems
If (e.getAttribute("id") = "show-history") Then
e.Click
Exit For
End If
Next e
End With
Set ie = Nothing
End Sub
我收到运行时错误 438,该对象不支持属性或方法。
我要先点击的元素的代码是:
<button class="btn btn-lg btn-trigger other-actions-btn" id="otherActionsButton" aria-haspopup="true" type="button" data-qa="toggle-other-actions" olive-menu-initialized="true" olive-menu-trigger="otherActionsMenu" olive-menu-position="below right" olive-menu="otherActionsMenu">Other Actions</button>
第二个按钮的代码是:
<button class="item button-link" type="button" data-qa="show-history" data-action="show:history">View History</button>
由于后台发生的事情,有时页面加载和所有可点击元素之间似乎存在延迟,我不确定这是否会导致问题?
欢迎任何想法!
詹姆斯
【问题讨论】:
标签: html vba web-scraping screen-scraping