JSoup - 每个表体的表行数

时间:2014-05-20 16:04:14

标签: java html jsoup

我有以下html表,我试图使用JSoup解析。

我正在解析它如下;

Elements table = document.select("table[class=MsoNormalTable]");
Elements tbody = table.select("tbody");
Elements tr = tbody.select("tr");
Elements td = tr.select("td");
Elements tableHeaders = td.select("p[class=MsoNormal]");

我怎样才能找出每个表体有多少表行?

    <p class="MsoNormal"><b><u><span lang="EN-US">€ SUPR:</span></u></b></p>
    <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="585" style="width:438.45pt; margin-left:-1.05pt; border-collapse:collapse">
        <tbody>
            <tr style="height:15.0pt">
                <td width="124" style="width:92.8pt; border:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Available on TW</span></b></p>
                </td>
                <td width="60" style="width:44.65pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Ticker</span></b></p>
                </td>
                <td width="85" style="width:64.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Coupon</span></b></p>
                </td>
                <td width="110" style="width:82.7pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Maturity Date
                        </span></b>
                    </p>
                </td>
                <td width="99" style="width:74.3pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">ISIN</span></b></p>
                </td>
                <td width="107" style="width:80.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">ISIN Location</span></b></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">06/05/2014</span></p>
                </td>
                <td width="60" nowrap="" valign="bottom" style="width:44.65pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal"><span style="color:black">OSEOFI </span></p>
                </td>
                <td width="85" nowrap="" style="width:64.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">1%</span></p>
                </td>
                <td width="110" nowrap="" style="width:82.7pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">25/10/2019</span></p>
                </td>
                <td width="99" nowrap="" valign="bottom" style="width:74.3pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal"><span style="color:black">FR0011898196 </span></p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">FR</span></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">07/05/2014</span></p>
                </td>
                <td width="60" nowrap="" valign="bottom" style="width:44.65pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal"><span style="color:black">ESM </span></p>
                </td>
                <td width="85" nowrap="" style="width:64.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">0.875%</span></p>
                </td>
                <td width="110" nowrap="" style="width:82.7pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">15/10/2019</span></p>
                </td>
                <td width="99" nowrap="" style="width:74.3pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">EU000A1U9829
                        </span>
                    </p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">DE</span></p>
                </td>
            </tr>
        </tbody>
    </table>
    <p class="MsoNormal"><u><span lang="EN-US"><span style="text-decoration:none">&nbsp;</span></span></u></p>
    <p class="MsoNormal"><u><span lang="EN-US"><span style="text-decoration:none">&nbsp;</span></span></u></p>
    <p class="MsoNormal"><b><u><span lang="EN-US">£ SUPR:</span></u></b></p>
    <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="606" style="width:454.25pt; margin-left:-1.05pt; border-collapse:collapse">
        <tbody>
            <tr style="height:15.0pt">
                <td width="124" style="width:92.8pt; border:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Available on TW</span></b></p>
                </td>
                <td width="70" style="width:52.15pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Ticker</span></b></p>
                </td>
                <td width="71" style="width:53.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Coupon</span></b></p>
                </td>
                <td width="115" style="width:86.2pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Maturity Date
                        </span></b>
                    </p>
                </td>
                <td width="97" style="width:72.8pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">ISIN</span></b></p>
                </td>
                <td width="130" style="width:97.3pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">XS ISIN Location</span></b></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">06/05/2014</span></p>
                </td>
                <td width="70" nowrap="" valign="bottom" style="width:52.15pt; border:none; border-bottom:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal"><span style="color:black">FMSWER </span></p>
                </td>
                <td width="71" nowrap="" style="width:53.0pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">FRN</span></p>
                </td>
                <td width="115" nowrap="" style="width:86.2pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">09/05/2016</span></p>
                </td>
                <td width="97" nowrap="" style="width:72.8pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">&nbsp;DE000A11QBT6&nbsp;&nbsp;
                        </span>
                    </p>
                </td>
                <td width="130" nowrap="" style="width:97.3pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">DE</span></p>
                </td>
            </tr>
        </tbody>
    </table>
    <p class="MsoNormal"><u><span lang="EN-US"><span style="text-decoration:none">&nbsp;</span></span></u></p>
    <p class="MsoNormal"><span lang="EN-US">&nbsp;</span></p>
    <p class="MsoNormal"><b><u><span lang="EN-US" style="color:black">$ SUPR: </span>
        </u></b><b><u><span lang="EN-US"></span></u></b>
    </p>
    <table class="MsoNormalTable" border="0" cellspacing="0" cellpadding="0" width="823" style="width:617.0pt; margin-left:-1.05pt; border-collapse:collapse">
        <tbody>
            <tr style="height:15.0pt">
                <td width="124" style="width:92.8pt; border:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Available on TW</span></b></p>
                </td>
                <td width="80" style="width:60.2pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Ticker</span></b></p>
                </td>
                <td width="100" style="width:75.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Coupon</span></b></p>
                </td>
                <td width="113" style="width:84.5pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Maturity Date
                        </span></b>
                    </p>
                </td>
                <td width="105" style="width:78.5pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">ISIN</span></b></p>
                </td>
                <td width="107" style="width:80.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">ISIN Location</span></b></p>
                </td>
                <td width="195" style="width:146.0pt; border:solid windowtext 1.0pt; border-left:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><b><span style="color:black">Benchmark</span></b></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">07/05/2014</span></p>
                </td>
                <td width="80" nowrap="" style="width:60.2pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">MP</span></p>
                </td>
                <td width="100" nowrap="" style="width:75.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">3.050</span></p>
                </td>
                <td width="113" nowrap="" style="width:84.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">14/05/2024</span></p>
                </td>
                <td width="105" nowrap="" valign="bottom" style="width:78.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal"><span style="color:black">US563469UD51 </span></p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">CA</span></p>
                </td>
                <td width="195" nowrap="" style="width:146.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">US912828WJ58</span></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">08/05/2014</span></p>
                </td>
                <td width="80" nowrap="" style="width:60.2pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">IBRD</span></p>
                </td>
                <td width="100" nowrap="" style="width:75.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">0.976</span></p>
                </td>
                <td width="113" nowrap="" style="width:84.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">09/05/2019</span></p>
                </td>
                <td width="105" nowrap="" style="width:78.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">XS1055866559</span></p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">XS</span></p>
                </td>
                <td width="195" nowrap="" style="width:146.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">3M LIBOR</span></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">09/05/2014</span></p>
                </td>
                <td width="80" nowrap="" valign="bottom" style="width:60.2pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">AUST
                        </span>
                    </p>
                </td>
                <td width="100" nowrap="" style="width:75.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">0.000</span></p>
                </td>
                <td width="113" nowrap="" style="width:84.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">07/05/2015</span></p>
                </td>
                <td width="105" nowrap="" style="width:78.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">XS1066373421</span></p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">AT</span></p>
                </td>
                <td width="195" nowrap="" style="width:146.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">US912828C814</span></p>
                </td>
            </tr>
            <tr style="height:15.0pt">
                <td width="124" nowrap="" style="width:92.8pt; border:solid windowtext 1.0pt; border-top:none; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">09/05/2014</span></p>
                </td>
                <td width="80" nowrap="" style="width:60.2pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">BNG</span></p>
                </td>
                <td width="100" nowrap="" style="width:75.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">FRN</span></p>
                </td>
                <td width="113" nowrap="" style="width:84.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">15/05/2014</span></p>
                </td>
                <td width="105" nowrap="" style="width:78.5pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">XS1068089025</span></p>
                </td>
                <td width="107" nowrap="" style="width:80.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">NL</span></p>
                </td>
                <td width="195" nowrap="" style="width:146.0pt; border-top:none; border-left:none; border-bottom:solid windowtext 1.0pt; border-right:solid windowtext 1.0pt; padding:0cm 5.4pt 0cm 5.4pt; height:15.0pt">
                    <p class="MsoNormal" align="center" style="text-align:center"><span style="color:black">3M LIBOR</span></p>
                </td>
            </tr>
        </tbody>
    </table>

2 个答案:

答案 0 :(得分:3)

只需使用尺寸方法。 document.select("table[class=MsoNormalTable] tbody")语句给出了所有tbody和形式,如果你选择tr并检查大小,你就会得到这个数字。

迭代每个tbody并获得像

这样的大小
Elements tables = document.select("table[class=MsoNormalTable] tbody");

int index = 0;
for(Element table : tables){
    System.out.println("Table : " + (++index) + " has " + table.select("tr").size() + " rows.");
}

答案 1 :(得分:0)

根据JavaDoc,此元素列表中的select()&#34; Find [s]匹配元素&#34;,表示返回仅限于您所在元素下的DOM元素搜索(如限制),size()返回接口Collection&#34;中的&#34;大小。这似乎表明在给定的DOM元素上使用select()后跟返回size()上的Elements将为您提供由Elements返回的所有tbody的大小/计数选择。您正在选择具有&#39; MsoNormal&#39;类的所有表,我在您的示例中看到的是3个表。然后,您获得tr,然后是td,然后是tbody。您基本上是获取所有表(至少是您显示的表),然后是所有tr,然后是所有tr等,等等。如果您想将计数限制为仅table位于单个表中,然后您需要将正在搜索的内容(即List<Element> s)限制为您要计算的单个表。

如果无法做到这一点,请从table选择中获取Elements,循环浏览每一个,然后使用Element选择将搜索限制为仅限于元件。这只是阅读API并弄清楚你需要做什么的问题。是否要单独搜索您返回的Element或{{1}}?