B4J Question SOLVED - MiniHtmlParser - Help

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I am trying to parse this code, It is a array of teams.

(Small sample of data reformatted to show more clearly)

<div class="pageSection bowlersSection"><h1 class="bowlerListTitle">Bowler List</h1>
<div class="table-responsive bowler-table leaderboard">
<table class="table table-striped nobreak bowlerTable">
<thead class="table-header">
<tr class="toprow">
<th class="text-center max-content-lane">Lane</th>
<th class="text-center max-content-team">Name</th>
<th class="text-center max-content-game">Avg</th>
<th class="text-center max-content-game">Ent<br>Avg</th>
<th class="text-center max-content-game">Hdcp</th>
<th class="text-center max-content-games">Games</th>
<th class="text-center max-content-game">Pins</th>
<th class="text-center max-content-high">Ind.<br>Points</th>
</tr>
</thead>

<tbody>
<tr class="table-team-header">
<td class="text-center">15</td>
<td class="bowler-team-name">24 - WE WANT STRIKES</td>
<td class="text-center">581</td>
<td class="text-center">581</td>
<td class="text-center">74</td>
<td class="text-center"></td>
<td class="text-center"></td>
<td class="text-center"></td>
</tr>

<tr>
<td></td>
<td class="bowler-team-name"><div class="avatar"><img class="avatarIMG" src="Bowlero%20Watauga%20-%20BWI%20-%20Week%203%20-%209_26_22_files/pin-icon.png"></div>Derrick Reagin</td>
<td class="text-center">191</td>
<td class="text-center">191</td>
<td class="text-center">27</td>
<td class="text-center">4</td>
<td class="text-center">731</td>
<td class="text-center">4</td>
</tr>

<tr>
<td></td>
<td class="bowler-team-name"><div class="avatar"><img class="avatarIMG" src="Bowlero%20Watauga%20-%20BWI%20-%20Week%203%20-%209_26_22_files/pin-icon.png"></div>Lamont Pringle</td>
<td class="text-center">186</td>
<td class="text-center">186</td>
<td class="text-center">31</td>
<td class="text-center">4</td>
<td class="text-center">818</td>
<td class="text-center">4</td>
</tr>

<tr>
<td></td>
<td class="bowler-team-name"><div class="avatar"><img class="avatarIMG" src="Bowlero%20Watauga%20-%20BWI%20-%20Week%203%20-%209_26_22_files/pin-icon.png"></div>Tracy Boiles</td>
<td class="text-center">204</td>
<td class="text-center">204</td>
<td class="text-center">16</td>
<td class="text-center">4</td>
<td class="text-center">734</td>
<td class="text-center">1</td>
</tr>
</tbody>
</table>

<table class="table table-striped nobreak bowlerTable">
<thead class="table-header">
<tr class="toprow">
<th class="text-center max-content-lane">Lane</th><th class="text-center max-content-team">Name</th><th class="text-center max-content-game">Avg</th><th

I want to get a list of
B4X:
<table class="table table-striped nobreak bowlerTable">
tables so I can then parse all the different data
This is what I am trying to do

B4X:
    HtmlParser.Initialize
    Dim root As HtmlNode = HtmlParser.Parse(File.ReadString(File.DirAssets, "LeaguePals.htm"))
   
    'Find the table element
    Dim BowlerList As HtmlNode = HtmlParser.FindNode(root, "div", HtmlParser.CreateHtmlAttribute("class", "table-responsive bowler-table leaderboard"))
   
    Dim Tables As List = HtmlParser.FindDirectNodes(BowlerList, "table", HtmlParser.CreateHtmlAttribute("class", "table table-striped nobreak bowlerTable"))

It seems to find the BolwerList but when I try to find the tables under it it fails.

Note: I am using Erels MiniHtmlParser as a starting point

Attached is B4J program.

Please ANY help you can give.

BobVal
 

Attachments

  • non-ui.zip
    13.1 KB · Views: 168

Robert Valentino

Well-Known Member
Licensed User
Longtime User
When I look are Bowler List and drill down I can see the entries in there but how do I get them out
1663796074970.png
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
An important tool for such tasks is the browser development console:

1663824896095.png


B4X:
Sub AppStart (Args() As String)
    HtmlParser.Initialize
    Dim root As HtmlNode = HtmlParser.Parse(File.ReadString(File.DirAssets, "LeaguePals.htm"))
    Dim tbody As HtmlNode = HtmlParser.FindNode(root, "tbody", HtmlParser.CreateHtmlAttribute("id", "leagueStandings"))
    Dim trs As List = HtmlParser.FindDirectNodes(tbody, "tr", Null)
    For Each tr As HtmlNode In trs
        Dim tds As List = HtmlParser.FindDirectNodes(tr, "td", Null)
        For i = 0 To tds.Size - 1
            Dim td As HtmlNode = tds.Get(i)
            Select i
                Case 0
                    Dim pos As HtmlNode = HtmlParser.FindNode(td, "span", HtmlParser.CreateHtmlAttribute("class", "team-pos ng-binding"))
                    Log("pos: " & HtmlParser.GetTextFromNode(pos, 0))
                Case 1
                    Log("Position: " & HtmlParser.GetTextFromNode(td, 0))
                Case 2
                    Log("Lane: " & HtmlParser.GetTextFromNode(td, 0))
                Case 3
                    Log("ID: " & HtmlParser.GetTextFromNode(HtmlParser.FindNode(td, "div", Null), 0))
            End Select
            
        Next
    Next
End Sub


Waiting for debugger to connect...
Program started.
pos: 1
Position: 28
Lane: 10
ID: Team 10
pos: 2
Position: 33
Lane: 16
ID: TNT
pos: 3
Position: 17
Lane: 21
ID: Team 21
pos: 4
Position: 34
Lane: 11
ID: #11 Old Balls
pos: 5
Position: 38
Lane: 20
ID: Team 20
pos: 6
Position: 27
Lane: 5
ID: BAD DAWGS
pos: 7
Position: 26
Lane: 3
ID: LECROY'S TOYS
pos: 8
Position: 15
Lane: 24
ID: WE WANT STRIKES
pos: 9
Position: 30
Lane: 7
ID: Team 7
pos: 10
Position: 20
Lane: 2
ID: Team 2
pos: 11
Position: 31
Lane: 14
ID: Team 14
pos: 12
Position: 39
Lane: 17
ID: Team 17
pos: 13
Position: 18
Lane: 26
ID: POCKET POUNDERS
pos: 14
Position: 22
Lane: 25
ID: LFG
pos: 15
Position: 36
Lane: 18
ID: Just Relax and Bowl
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Thanks for trying.

I'm only trying to get the bowler list and it is not setup the same way.

1663855104771.png


This line gets me the 1st team table
B4X:
        Dim Table     As HtmlNode = HtmlParser.FindNode(root, "table", HtmlParser.CreateHtmlAttribute("class", "table table-striped nobreak bowlerTable"))

But I can't get the rest of the teams. There is a "table table-striped nobreak bowlerTable" table for each team


I'll keep trying
 
Last edited:
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Got it

B4X:
    Dim BowlerList     As HtmlNode = HtmlParser.FindNode(root, "div", HtmlParser.CreateHtmlAttribute("class", "pageSection bowlersSection"))    '"table-responsive bowler-table leaderboard"))

    If  BowlerList.IsInitialized Then
        Dim LeaderBoard As HtmlNode = HtmlParser.FindNode(BowlerList, "div", HtmlParser.CreateHtmlAttribute("class", "table-responsive bowler-table leaderboard"))  

        If  LeaderBoard.IsInitialized Then
            Dim Teams   As List    = HtmlParser.FindDirectNodes(LeaderBoard, "table", HtmlParser.CreateHtmlAttribute("class", "table table-striped nobreak bowlerTable"))
        end if
    end if
 
Upvote 0
Top