VBA检查是否存在div是否存在 我正在尝试确定html中是否存在div。 在这种情况下,DIV仅表示一个人无法访问正在刮擦的URL。 我有这个。 即作为InternetEx的昏暗...

问题描述 投票:0回答:1

	

html.getElementsByClassName

返回元素的集合,而不是单个元素,您应该检查该集合是否有任何项目,而不是直接检查它是否是Nothingexample no permissions.

Sub test() Dim ie As InternetExplorer Dim html As HTMLDocument Dim checkList As IHTMLElementCollection Dim url As String url = "https://stackoverflow.com/questions/79413010/vba-check-if-div-exists-or-not" ' Update this with your target URL Set ie = New InternetExplorer ie.Visible = True ie.navigate url ' Wait until IE is done loading page Do While ie.READYSTATE <> READYSTATE_COMPLETE Application.StatusBar = "Trying to go to " & url DoEvents Loop Set html = ie.Document ' changed for testing purposes Set checkList = html.getElementsByClassName("s-topbar--skip-link") Check if any error notifications exist If checkList.Length > 0 Then MsgBox "Error notification found. Exiting the subroutine." Exit Sub Else ' Continue with your logic if no error notification is found MsgBox "No error notifications detected. Continuing..." ' << Add your continuation logic here >> End If ' Clean up ie.Quit Set ie = Nothing Set html = Nothing Set checkList = Nothing End Sub
vba internet-explorer
1个回答
0
投票

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.