HTMLTagAttributeValue

Reads value of certain tag attribute from certain attribute
Identify attribute as first attribute matching ...
    HTMLBlock                Full HTML Block (page sorce code)    Required
    FirstTag                'a' in < a ....>link< /a>                Required
In addition, you may also provide one of below ...
    FirstTag_Name        'name' in a tag < a name="">Link< /a>
    FirstTag_ID            'id' in a tag < a id="somthing">Link< /a>
    FirstTag_Class        'class' in a tag < a class="something">Link< /a>

This is a more advanced version of similar ReadHTMLTag


Public

Tested

My Own Work
Function HTMLTagAttributeValue(HTMLBlock, FirstTag, FirstTag_Name, FirstTag_ID, FirstTag_Class, TagAttributeName)
    ' Reads value of certain tag attribute from certain attribute
    ' Identify attribute as first attribute matching ...
    '    HTMLBlock                Full HTML Block (page source code)    Required
    '    FirstTag                'a' in link                Required
    ' In addition, you may also provide one of below ...
    '    FirstTag_Name        'name' in a tag Link
    '    FirstTag_ID            'id' in a tag Link
    '    FirstTag_Class        'class' in a tag Link
    '
    '
    HTMLTagAttributeValue = ""
    Tag1 = UCase("<" & FirstTag)
    Tag9 = ">"
    Tag1Ct = InStr(1, UCase(HTMLBlock), Tag1)
    Tag9Ct = InStr(Tag1Ct, UCase(HTMLBlock), Tag9)
    If FirstTag = "" Then Exit Function
    If Tag1Ct = 0 Then Exit Function
    Found1 = ""
    Rett = ""
    Do
        FullTag = Mid(HTMLBlock, Tag1Ct, Tag9Ct - Tag1Ct)
        For Each TagAttr In Split(FullTag, " ")
            TagAttr1 = UCase(Replace(Replace(CutString(TagAttr, , "="), "'", ""), """", ""))
            TagAttr2 = UCase(Replace(Replace(CutString(TagAttr, "=", ""), "'", ""), """", ""))
            If FirstTag_Name > "" And TagAttr1 = "NAME" And TagAttr2 = UCase(FirstTag_Name) Then
                Found1 = FullTag
                Exit For
            ElseIf FirstTag_ID > "" And TagAttr1 = "ID" And TagAttr2 = UCase(FirstTag_ID) Then
                Found1 = FullTag
                Exit For
            ElseIf FirstTag_Class > "" And TagAttr1 = "CLASS" And TagAttr2 = UCase(FirstTag_Class) Then
                Found1 = FullTag
                Exit For
            End If
        Next
        If Found1 > "" Then
            Rett = CutString8(UCase(HTMLBlock), " " & UCase(TagAttributeName) & "=", , " ", ">")
            Exit Do
        End If
        Tag1Ct = InStr(Tag9Ct, UCase(HTMLBlock), Tag1)
        If Tag1Ct = 0 Then Exit Do
        Tag9Ct = InStr(Tag1Ct, UCase(HTMLBlock), Tag9)
        If Tag9Ct = 0 Then Exit Do
    Loop
ByeBye:
    HTMLTagAttributeValue = CStr(Trim(Replace(Replace(Rett, "'", ""), """", "")))
End Function

HTMLBlock, FirstTag, FirstTag_Name, FirstTag_ID, FirstTag_Class, TagAttributeName

Views 108 Downloads 27

Classic ASP Texts + Strings
ANmarAmdeen
802
Attachments
Revisions

v2.0