Android Question parser text from html by using MiniHtmlParser

Binary01

Active Member
Licensed User
Longtime User
Hi,

I get '*CaptionText in my code. Now I want Text ' * Last Update 14/01/2022 09:58:03' that nextline of <br> tag by using MiniHtmlParser.

Thanks.

B4X:
Sub AppStart (Args() As String)
    Dim s As String = $"
    <body>
<table class="table-info">
    <caption style="text-align: right;">
        <span class="set-color-gray set-color-graylight">* CaptionText </span><br>
        * Last Update 14/01/2022 09:58:03
    </caption>
' *******
</table>
</body>"$

    Dim  HtmlParser As MiniHtmlParser
    HtmlParser.Initialize
    Dim root As HtmlNode = HtmlParser.Parse(s)
    Dim Table As HtmlNode = HtmlParser.FindNode(root, "table", HtmlParser.CreateHtmlAttribute("class", "table-info"))
    If Table.IsInitialized Then      
        Dim caption As List = HtmlParser.FindDirectNodes(Table, "caption", Null)
        For i = 0 To caption.Size - 1
            Dim spans As List = HtmlParser.FindDirectNodes(caption.Get(i), "span", Null)
            For Each span As HtmlNode In spans
                Log(HtmlParser.GetTextFromNode(span, 0))
            Next
        Next
    Else
        Log("not found!!!")
    End If
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub AppStart (Args() As String)
    Dim s As String = $"
    <body>
<table class="table-info">
    <caption style="text-align: right;">
        <span class="set-color-gray set-color-graylight">* CaptionText </span><br>
        * Last Update 14/01/2022 09:58:03
    </caption>
    ' *******
</table>
</body>"$

    Dim  HtmlParser As MiniHtmlParser
    HtmlParser.Initialize
    Dim root As HtmlNode = HtmlParser.Parse(s)
    Dim Table As HtmlNode = HtmlParser.FindNode(root, "table", HtmlParser.CreateHtmlAttribute("class", "table-info"))
    If Table.IsInitialized Then
        Dim caption As HtmlNode = HtmlParser.FindNode(Table, "caption", Null)
        For Each node As HtmlNode In caption.Children
            Dim text As HtmlNode = HtmlParser.FindNode(node, "text", Null)
            If text.IsInitialized Then
                Log(HtmlParser.GetAttributeValue(text, "value", ""))
            End If
        Next
    Else
        Log("not found!!!")
    End If
End Sub
 
Upvote 0
Top