如何使用Jsoup在Java中从<tr>并排打印<th>和<td>?

这是该站点的html代码:

<table class="product-specs">
    <tbody>

       <tr data-specid="8751">
            <th>Touch Bar</th>
            <td>Ne</td>
       </tr>

       <tr data-specid="62">
            <th>RAM memorija</th>
            <td>16GB</td>
       </tr>

这是我的Java代码:

Document doc = Jsoup.connect("https://www.gigatron.rs/laptop_racunari/hp_pavilion_gaming__15ec0024nm__8pk23ea-299138").get();
System.out.println("ok");
Elements specName = doc.select(".product-specs tbody tr th");
Elements specHave = doc.select(".product-specs tbody tr td");
            System.out.println(specName.html() + " " + specHave.html());

It just prints specName first and underneath it specHave. Can i some how print it side by side?

评论