首先循环选定的标签,然后循环所有标签

Looping selected Tag first and then all tags

本文关键字:标签 循环 然后      更新时间:2023-09-26

在VB6中,我想通过一个web浏览器控件中的所有html标签循环。当html内容很大时,它会变得很慢。以下是我的要求。

我想获得一个具有特定名称的"a"(锚)标记,该名称在该文档中是唯一的。(例子)。在得到这个标签我想循环通过所有的html标签,直到我得到另一个"A"标签与另一个特定的名称。(例

所以我使用下面的代码。代码是通过检查属性名中的一些字符来完成的,因为它以相同的方式工作。代码不符合我的要求,我解释为我做了另一种方式。

Dim bkm As Boolean
Dim hw2 As HTMLWindow2
 For Each ele In hw2.Document.All
        If ele.getAttribute("name") = mybkm Then 'mybkm  variable having name of tag
            bkm = True
            ele.Style.cssText = "background-color:#FFFFEB;" & ele.Style.cssText
        ElseIf bkm = True And InStr(ele.outerHTML, "name=BKM") = 0) Then
            ele.Style.cssText = "background-color:#FFFFEB;" & ele.Style.cssText
        ElseIf InStr(ele.getAttribute("name"), "BKM") > 0 Then
            If bkm = True Then
                bkm = False
                Exit For
            End If
        End If
    Next

但是在我的这个得到第一次出现的标签与该名称变得非常缓慢(它需要整个过程的时间的90%左右)由于大no。如P,br,A,table等标签

所以我计划获得具有特定名称的第一个"A"标签(可能只是通过循环"A"标签),然后循环所有标签,直到我得到下一个"A"标签。

那怎么做呢?

Try like this - 
Dim i As Integer
Dim anchorElement As HTMLAnchorElement = wbMain.Document.All.getElementByTagName("A")(0)
For i = 0 To anchorElement.attributes.length - 1
  MsgBox anchorElement.attributes.item(i).name & "=" & anchorElement.attributes.item(i).value
Next i