Reads value of certain tag attribute from certain attribute
Identify attribute as first attribute matching ...
HTMLBlock Full HTML Block (page source code) Required
FindFirstTag_byTag 'a' in link Required
In addition, you may also provide one of below ...
FindFirstTag_ByName 'name' in a tag Link
FindFirstTag_ByID 'id' in a tag Link
FindFirstTag_ByClass 'class' in a tag Link
The function then will return the value of the attribute in ReturnTagAttributeName for that found tag.
This is a more advanced version of similar ReadHTMLTag
Edit 2023-11-07: Changed names of parameters to describe function more.
Function HTMLTagAttributeValue(HTMLBlock, FindFirstTag_byTag, FindFirstTag_ByName, FindFirstTag_ByID, FindFirstTag_ByClass, ReturnTagAttributeName)
' Reads value of certain tag attribute from certain attribute
' Identify attribute as first attribute matching ...
' HTMLBlock Full HTML Block (page source code) Required
' FindFirstTag_byTag 'a' in <a .... >link </a > Required
' In addition, you may also provide one of below ...
' FindFirstTag_ByName 'name' in a tag <a name="" >Link </a >
' FindFirstTag_ByID 'id' in a tag <a id="something" >Link </a >
' FindFirstTag_ByClass 'class' in a tag <a class="something" >Link </a >
' the function then will return the value of the attribute in ReturnTagAttributeName for that found tag.
'
HTMLTagAttributeValue = ""
Tag1 = UCase(" <" & FindFirstTag_byTag)
Tag9 = " >"
Tag1Ct = InStr(1, UCase(HTMLBlock), Tag1)
Tag9Ct = InStr(Tag1Ct, UCase(HTMLBlock), Tag9)
If FindFirstTag_byTag = "" Then Exit Function
If Tag1Ct = 0 Then Exit Function
Found1 = ""
Rett = ""
Do
FullTag = Mid(HTMLBlock, Tag1Ct, Tag9Ct - Tag1Ct)
If FindFirstTag_ByName = "" And FindFirstTag_ByID = "" And FindFirstTag_ByClass = "" Then
Rett = CutString8(UCase(FullTag), " " & UCase(ReturnTagAttributeName) & "=", "", " ", " >", 1)
Exit Do
End If
For Each TagAttr In Split(FullTag, " ")
TagAttr1 = UCase(Replace(Replace(CutString(TagAttr, , "="), "'", ""), """", ""))
TagAttr2 = UCase(Replace(Replace(CutString(TagAttr, "=", ""), "'", ""), """", ""))
If FindFirstTag_ByName > "" And TagAttr1 = "NAME" And TagAttr2 = UCase(FindFirstTag_ByName) Then
Found1 = FullTag
Exit For
ElseIf FindFirstTag_ByID > "" And TagAttr1 = "ID" And TagAttr2 = UCase(FindFirstTag_ByID) Then
Found1 = FullTag
Exit For
ElseIf FindFirstTag_ByClass > "" And TagAttr1 = "CLASS" And TagAttr2 = UCase(FindFirstTag_ByClass) Then
Found1 = FullTag
Exit For
End If
Next
If Found1 > "" Then
Rett = CutString8(UCase(HTMLBlock), " " & UCase(ReturnTagAttributeName) & "=", "", " ", " >", 1)
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
' Reads value of certain tag attribute from certain attribute
' Identify attribute as first attribute matching ...
' HTMLBlock Full HTML Block (page source code) Required
' FindFirstTag_byTag 'a' in <a .... >link </a > Required
' In addition, you may also provide one of below ...
' FindFirstTag_ByName 'name' in a tag <a name="" >Link </a >
' FindFirstTag_ByID 'id' in a tag <a id="something" >Link </a >
' FindFirstTag_ByClass 'class' in a tag <a class="something" >Link </a >
' the function then will return the value of the attribute in ReturnTagAttributeName for that found tag.
'
HTMLTagAttributeValue = ""
Tag1 = UCase(" <" & FindFirstTag_byTag)
Tag9 = " >"
Tag1Ct = InStr(1, UCase(HTMLBlock), Tag1)
Tag9Ct = InStr(Tag1Ct, UCase(HTMLBlock), Tag9)
If FindFirstTag_byTag = "" Then Exit Function
If Tag1Ct = 0 Then Exit Function
Found1 = ""
Rett = ""
Do
FullTag = Mid(HTMLBlock, Tag1Ct, Tag9Ct - Tag1Ct)
If FindFirstTag_ByName = "" And FindFirstTag_ByID = "" And FindFirstTag_ByClass = "" Then
Rett = CutString8(UCase(FullTag), " " & UCase(ReturnTagAttributeName) & "=", "", " ", " >", 1)
Exit Do
End If
For Each TagAttr In Split(FullTag, " ")
TagAttr1 = UCase(Replace(Replace(CutString(TagAttr, , "="), "'", ""), """", ""))
TagAttr2 = UCase(Replace(Replace(CutString(TagAttr, "=", ""), "'", ""), """", ""))
If FindFirstTag_ByName > "" And TagAttr1 = "NAME" And TagAttr2 = UCase(FindFirstTag_ByName) Then
Found1 = FullTag
Exit For
ElseIf FindFirstTag_ByID > "" And TagAttr1 = "ID" And TagAttr2 = UCase(FindFirstTag_ByID) Then
Found1 = FullTag
Exit For
ElseIf FindFirstTag_ByClass > "" And TagAttr1 = "CLASS" And TagAttr2 = UCase(FindFirstTag_ByClass) Then
Found1 = FullTag
Exit For
End If
Next
If Found1 > "" Then
Rett = CutString8(UCase(HTMLBlock), " " & UCase(ReturnTagAttributeName) & "=", "", " ", " >", 1)
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, FindFirstTag_byTag, FindFirstTag_ByName, FindFirstTag_ByID, FindFirstTag_ByClass, ReturnTagAttributeName
Views 438
Downloads 133
CodeID
DB ID