Q:

Kotlin: get the data inside a  with Jsoup

i have this HTML
<table class="table">

       <tr >
         <th colspan="3" ><center>2019-01-01<br>Some Text  </center></th>
       </tr>

i need get 2019-01-01, i try this in Kotlin:
var table = doc.select("table.table")[1]
            var rows = table.select("tr")
            for (row in rows) {
                val th = row.select("th")
                if (th.attr("colspan")=="3"){
                    val date= th.select("center")
                }

but this get all the data, how can i just extract what's inside the <center> and before <br>

A:

If you want to extract the text before the <br>, you can split it:
val date = th.select("center").html().split("<br>").first()

This grabs the entire <center> tag, gets the html representation, splits it using <br> as a delimiter, and then gets the first() value (the left hand side).

